Bug 1161200 - Only show "Edit Site Settings" when actionable. r=margaret

This commit is contained in:
Chenxia Liu 2015-06-12 18:03:04 -07:00
parent 361dcda6cb
commit 22e3853dcf
4 changed files with 46 additions and 10 deletions

View File

@ -84,7 +84,8 @@
android:textColor="@color/link_blue"
android:layout_marginTop="@dimen/doorhanger_section_padding_large"
android:layout_marginBottom="@dimen/doorhanger_padding"
android:text="@string/contextmenu_site_settings"/>
android:text="@string/contextmenu_site_settings"
android:visibility="gone"/>
</LinearLayout>
</LinearLayout>

View File

@ -74,6 +74,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
private TextView mOwnerLabel;
private TextView mOwner;
private TextView mVerifier;
private TextView mSiteSettingsLink;
private View mDivider;
@ -88,6 +89,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
mContentButtonClickListener = new ContentNotificationButtonListener();
EventDispatcher.getInstance().registerGeckoThreadListener(this, "Doorhanger:Logins");
EventDispatcher.getInstance().registerGeckoThreadListener(this, "Permissions:CheckResult");
}
@Override
@ -116,14 +118,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
mVerifier = (TextView) mIdentityKnownContainer.findViewById(R.id.verifier);
mDivider = mIdentity.findViewById(R.id.divider_doorhanger);
final TextView siteSettingsLink = (TextView) mIdentity.findViewById(R.id.site_settings_link);
siteSettingsLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null));
dismiss();
}
});
mSiteSettingsLink = (TextView) mIdentity.findViewById(R.id.site_settings_link);
}
private void updateIdentity(final SiteIdentity siteIdentity) {
@ -137,6 +132,9 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
if (isIdentityKnown) {
updateIdentityInformation(siteIdentity);
}
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(
"Permissions:Check", null));
}
@Override
@ -154,6 +152,24 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
} catch (JSONException e) {
Log.e(LOGTAG, "Error accessing logins in Doorhanger:Logins message", e);
}
} else if ("Permissions:CheckResult".equals(event)) {
final boolean hasPermissions = geckoObject.optBoolean("hasPermissions", false);
if (hasPermissions) {
mSiteSettingsLink.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Permissions:Get", null));
dismiss();
}
});
}
ThreadUtils.postToUiThread(new Runnable() {
@Override
public void run() {
mSiteSettingsLink.setVisibility(hasPermissions ? View.VISIBLE : View.GONE);
}
});
}
}
@ -466,6 +482,7 @@ public class SiteIdentityPopup extends AnchoredPopup implements GeckoEventListen
void destroy() {
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Doorhanger:Logins");
EventDispatcher.getInstance().unregisterGeckoThreadListener(this, "Permissions:CheckResult");
}
@Override

View File

@ -51,8 +51,11 @@ var PermissionsHelper = {
observe: function observe(aSubject, aTopic, aData) {
let uri = BrowserApp.selectedBrowser.currentURI;
let check = false;
switch (aTopic) {
case "Permissions:Check":
check = true;
case "Permissions:Get":
let permissions = [];
for (let i = 0; i < this._permissonTypes.length; i++) {
@ -63,6 +66,13 @@ var PermissionsHelper = {
if (value == Services.perms.UNKNOWN_ACTION)
continue;
if (check) {
Messaging.sendRequest({
type: "Permissions:CheckResult",
hasPermissions: true
});
return;
}
// Get the strings that correspond to the permission type
let typeStrings = this._permissionStrings[type];
let label = Strings.browser.GetStringFromName(typeStrings["label"]);
@ -79,6 +89,14 @@ var PermissionsHelper = {
});
}
if (check) {
Messaging.sendRequest({
type: "Permissions:CheckResult",
hasPermissions: false
});
return;
}
// Keep track of permissions, so we know which ones to clear
this._currentPermissions = permissions;

View File

@ -148,7 +148,7 @@ let lazilyLoadedObserverScripts = [
["MemoryObserver", ["memory-pressure", "Memory:Dump"], "chrome://browser/content/MemoryObserver.js"],
["ConsoleAPI", ["console-api-log-event"], "chrome://browser/content/ConsoleAPI.js"],
["FindHelper", ["FindInPage:Opened", "FindInPage:Closed", "Tab:Selected"], "chrome://browser/content/FindHelper.js"],
["PermissionsHelper", ["Permissions:Get", "Permissions:Clear"], "chrome://browser/content/PermissionsHelper.js"],
["PermissionsHelper", ["Permissions:Check", "Permissions:Get", "Permissions:Clear"], "chrome://browser/content/PermissionsHelper.js"],
["FeedHandler", ["Feeds:Subscribe"], "chrome://browser/content/FeedHandler.js"],
["Feedback", ["Feedback:Show"], "chrome://browser/content/Feedback.js"],
["SelectionHandler", ["TextSelection:Get"], "chrome://browser/content/SelectionHandler.js"],