summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 19:14:45 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-03-02 19:14:45 +0000
commit1ed5cd0117990de7a4bd439d8295263b275725b8 (patch)
tree55559a4a465b5fcc21c8c068583949458796612f
parent70daf0b18defd88e97f5f9ebcc9486c22898b66b (diff)
downloadchromium_src-1ed5cd0117990de7a4bd439d8295263b275725b8.zip
chromium_src-1ed5cd0117990de7a4bd439d8295263b275725b8.tar.gz
chromium_src-1ed5cd0117990de7a4bd439d8295263b275725b8.tar.bz2
Further tweaks to incognito extensions.
- Add a warning to the incognito new tab page that your extensions are disabled in that mode. - Toggling an extension in incognito will reload the extension, fixing a bug where browser actions in existing incognito windows would not get updated. BUG=36292 BUG=32365 TEST=run chrome with --enable-experimental-extension-apis and some extensions loaded, and open an incognito window. Enable some extensions in incognito and make sure things work. Review URL: http://codereview.chromium.org/660220 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40403 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/app/generated_resources.grd5
-rw-r--r--chrome/browser/dom_ui/ntp_resource_cache.cc8
-rw-r--r--chrome/browser/extensions/extension_browsertest.cc13
-rw-r--r--chrome/browser/extensions/extension_message_service.cc11
-rw-r--r--chrome/browser/extensions/extension_process_manager.cc13
-rw-r--r--chrome/browser/extensions/extensions_service.cc8
-rw-r--r--chrome/browser/extensions/user_script_master.cc19
-rw-r--r--chrome/browser/resources/incognito_tab.html22
-rw-r--r--chrome/common/notification_type.h4
9 files changed, 56 insertions, 47 deletions
diff --git a/chrome/app/generated_resources.grd b/chrome/app/generated_resources.grd
index bc8b8c1..b358b59 100644
--- a/chrome/app/generated_resources.grd
+++ b/chrome/app/generated_resources.grd
@@ -5524,6 +5524,11 @@ Keep your key file in a safe place. You will need it to create new versions of y
<ph name="END_LIST">&lt;/ul&gt;</ph>
<ph name="BEGIN_LINK">&lt;a href="$1"&gt;</ph>Learn more<ph name="END_LINK">&lt;/a&gt;</ph> about incognito browsing.
</message>
+ <message name="IDS_NEW_TAB_OTR_EXTENSIONS_MESSAGE"
+ desc="Explanation in a new OTR window that extensions have been disabled while in OTR.">
+ Because Google Chrome does not control how extensions handle your personal data, all extensions have been disabled for incognito windows. You can reenable them individually in the
+ <ph name="BEGIN_LINK">&lt;a href="$1"&gt;</ph>extensions manager<ph name="END_LINK">&lt;/a&gt;</ph>.
+ </message>
<message name="IDS_NEW_TAB_RECENTLY_CLOSED_WINDOW_SINGLE"
desc="Title of recently closed windows in the recently closed section of the new tab page when the window has a single tab">
1 Tab
diff --git a/chrome/browser/dom_ui/ntp_resource_cache.cc b/chrome/browser/dom_ui/ntp_resource_cache.cc
index 85b8e18..63db41c 100644
--- a/chrome/browser/dom_ui/ntp_resource_cache.cc
+++ b/chrome/browser/dom_ui/ntp_resource_cache.cc
@@ -217,6 +217,14 @@ void NTPResourceCache::CreateNewTabIncognitoHTML() {
localized_strings.SetString(L"content",
l10n_util::GetStringF(IDS_NEW_TAB_OTR_MESSAGE,
GetUrlWithLang(kLearnMoreIncognitoUrl)));
+ localized_strings.SetString(L"extensionsmessage",
+ l10n_util::GetStringF(IDS_NEW_TAB_OTR_EXTENSIONS_MESSAGE,
+ ASCIIToWide(chrome::kChromeUIExtensionsURL)));
+ bool show_extensions_disabled =
+ CommandLine::ForCurrentProcess()->HasSwitch(
+ switches::kEnableExperimentalExtensionApis);
+ localized_strings.SetString(L"showextensionsmessage",
+ show_extensions_disabled ? "true" : "false");
bool bookmark_bar_attached = profile_->GetPrefs()->GetBoolean(
prefs::kShowBookmarkBar);
localized_strings.SetString(L"bookmarkbarattached",
diff --git a/chrome/browser/extensions/extension_browsertest.cc b/chrome/browser/extensions/extension_browsertest.cc
index d96d6dc..843052c 100644
--- a/chrome/browser/extensions/extension_browsertest.cc
+++ b/chrome/browser/extensions/extension_browsertest.cc
@@ -69,8 +69,21 @@ bool ExtensionBrowserTest::LoadExtensionImpl(const FilePath& path,
return false;
if (incognito_enabled) {
+ // Enable the incognito bit in the extension prefs. The call to
+ // OnExtensionInstalled ensures the other extension prefs are set up with
+ // the defaults. Note that toggling incognito reloads the extension, so
+ // we have to run a modal loop to wait for that.
+ NotificationRegistrar registrar;
+ registrar.Add(this, NotificationType::EXTENSION_LOADED,
+ NotificationService::AllSources());
+
Extension* extension = service->extensions()->at(num_after - 1);
+ service->extension_prefs()->OnExtensionInstalled(extension);
service->SetIsIncognitoEnabled(extension->id(), true);
+
+ MessageLoop::current()->PostDelayedTask(
+ FROM_HERE, new MessageLoop::QuitTask, kTimeoutMs);
+ ui_test_utils::RunMessageLoop();
}
return WaitForExtensionHostsToLoad();
diff --git a/chrome/browser/extensions/extension_message_service.cc b/chrome/browser/extensions/extension_message_service.cc
index dd464ea..a58c600 100644
--- a/chrome/browser/extensions/extension_message_service.cc
+++ b/chrome/browser/extensions/extension_message_service.cc
@@ -142,8 +142,12 @@ void ExtensionMessageService::ProfileDestroyed() {
void ExtensionMessageService::AddEventListener(const std::string& event_name,
int render_process_id) {
- DCHECK(RenderProcessHost::FromID(render_process_id)) <<
- "Adding event listener to a non-existant RenderProcessHost.";
+ // It is possible that this RenderProcessHost is being destroyed. If that is
+ // the case, we'll have already removed his listeners, so do nothing here.
+ RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
+ if (!rph || rph->ListenersIterator().IsAtEnd())
+ return;
+
DCHECK_EQ(MessageLoop::current()->type(), MessageLoop::TYPE_UI);
DCHECK_EQ(listeners_[event_name].count(render_process_id), 0u) << event_name;
listeners_[event_name].insert(render_process_id);
@@ -156,8 +160,7 @@ void ExtensionMessageService::AddEventListener(const std::string& event_name,
void ExtensionMessageService::RemoveEventListener(const std::string& event_name,
int render_process_id) {
- // It is possible that this RenderProcessHost is being destroyed. If that is
- // the case, we'll have already removed his listeners, so do nothing here.
+ // The RenderProcessHost may be destroyed. See AddEventListener.
RenderProcessHost* rph = RenderProcessHost::FromID(render_process_id);
if (!rph || rph->ListenersIterator().IsAtEnd())
return;
diff --git a/chrome/browser/extensions/extension_process_manager.cc b/chrome/browser/extensions/extension_process_manager.cc
index 7ecee27..3121d3c 100644
--- a/chrome/browser/extensions/extension_process_manager.cc
+++ b/chrome/browser/extensions/extension_process_manager.cc
@@ -232,19 +232,6 @@ void ExtensionProcessManager::Observe(NotificationType type,
break;
}
- case NotificationType::EXTENSION_INCOGNITO_CHANGED: {
- Extension* extension =
- Details<std::pair<Extension*, bool> >(details).ptr()->first;
- bool incognito_enabled =
- Details<std::pair<Extension*, bool> >(details).ptr()->second;
- RenderProcessHost* rph = GetExtensionProcess(extension->id());
- if (rph) {
- rph->Send(new ViewMsg_Extension_ExtensionSetIncognitoEnabled(
- extension->id(), incognito_enabled));
- }
- break;
- }
-
case NotificationType::EXTENSION_HOST_DESTROYED: {
ExtensionHost* host = Details<ExtensionHost>(details).ptr();
all_hosts_.erase(host);
diff --git a/chrome/browser/extensions/extensions_service.cc b/chrome/browser/extensions/extensions_service.cc
index 0a5f145..77f7f48 100644
--- a/chrome/browser/extensions/extensions_service.cc
+++ b/chrome/browser/extensions/extensions_service.cc
@@ -552,14 +552,10 @@ bool ExtensionsService::IsIncognitoEnabled(const std::string& extension_id) {
void ExtensionsService::SetIsIncognitoEnabled(const std::string& extension_id,
bool enabled) {
- Extension* extension = GetExtensionByIdInternal(extension_id, true, true);
extension_prefs_->SetIsIncognitoEnabled(extension_id, enabled);
- std::pair<Extension*, bool> details(extension, enabled);
- NotificationService::current()->Notify(
- NotificationType::EXTENSION_INCOGNITO_CHANGED,
- Source<Profile>(profile_),
- Details<std::pair<Extension*, bool> >(&details));
+ DCHECK(GetExtensionByIdInternal(extension_id, true, true));
+ ReloadExtension(extension_id);
}
void ExtensionsService::CheckForExternalUpdates() {
diff --git a/chrome/browser/extensions/user_script_master.cc b/chrome/browser/extensions/user_script_master.cc
index 9506efd..db84280 100644
--- a/chrome/browser/extensions/user_script_master.cc
+++ b/chrome/browser/extensions/user_script_master.cc
@@ -294,8 +294,6 @@ UserScriptMaster::UserScriptMaster(const FilePath& script_dir, Profile* profile)
Source<Profile>(profile_));
registrar_.Add(this, NotificationType::EXTENSION_LOADED,
Source<Profile>(profile_));
- registrar_.Add(this, NotificationType::EXTENSION_INCOGNITO_CHANGED,
- Source<Profile>(profile_));
registrar_.Add(this, NotificationType::EXTENSION_UNLOADED,
Source<Profile>(profile_));
}
@@ -350,23 +348,6 @@ void UserScriptMaster::Observe(NotificationType type,
StartScan();
break;
}
- case NotificationType::EXTENSION_INCOGNITO_CHANGED: {
- // Toggle the incognito_enabled bit for any content scripts inside the
- // extension.
- Extension* extension =
- Details<std::pair<Extension*, bool> >(details).ptr()->first;
- bool incognito_enabled =
- Details<std::pair<Extension*, bool> >(details).ptr()->second;
- for (UserScriptList::iterator iter = lone_scripts_.begin();
- iter != lone_scripts_.end(); ++iter) {
- if (iter->extension_id() == extension->id())
- (*iter).set_incognito_enabled(incognito_enabled);
- }
- if (extensions_service_ready_)
- StartScan();
- break;
- }
-
case NotificationType::EXTENSION_UNLOADED: {
// Remove any content scripts.
Extension* extension = Details<Extension>(details).ptr();
diff --git a/chrome/browser/resources/incognito_tab.html b/chrome/browser/resources/incognito_tab.html
index fac60e1..e0c8933 100644
--- a/chrome/browser/resources/incognito_tab.html
+++ b/chrome/browser/resources/incognito_tab.html
@@ -1,5 +1,5 @@
<!DOCTYPE html>
-<html i18n-values="dir:textdirection;bookmarkbarattached:bookmarkbarattached">
+<html i18n-values="dir:textdirection;bookmarkbarattached:bookmarkbarattached;showextensionsmessage:showextensionsmessage">
<head>
<title i18n-content="title"></title>
<style>
@@ -25,6 +25,22 @@ html[dir="rtl"] .icon {
margin-right:auto;
margin-top:66px;
}
+html[showextensionsmessage="true"] .extensionsmessage {
+ color:black;
+ padding:10px 10px 10px 10px;
+ max-width:600px;
+ margin-left:auto;
+ margin-right:auto;
+ margin-top:5px;
+}
+html[showextensionsmessage="false"] .extensionsmessage {
+ display:none;
+}
+.extensionicon {
+ float:left;
+ margin:10px 5px 0 0px;
+ width:30px;
+}
</style>
<script>
// Until themes can clear the cache, force-reload the theme stylesheet.
@@ -38,6 +54,10 @@ document.write('<link id="incognitothemecss" rel="stylesheet" ' +
<img src="../../app/theme/otr_icon_standalone.png" class="icon" />
<span i18n-values=".innerHTML:content"></span>
</div>
+<div class="extensionsmessage" i18n-values=".style.fontFamily:fontfamily;.style.fontSize:fontsize">
+ <img src="../../app/theme/extensions_section.png" class="extensionicon" />
+ <span i18n-values=".innerHTML:extensionsmessage"></span>
+</div>
</body>
<script>
function themeChanged() {
diff --git a/chrome/common/notification_type.h b/chrome/common/notification_type.h
index 2abe637..ef3c0f9 100644
--- a/chrome/common/notification_type.h
+++ b/chrome/common/notification_type.h
@@ -677,10 +677,6 @@ class NotificationType {
// details are an Extension*, and the source is a Profile*.
EXTENSION_UPDATE_DISABLED,
- // Sent when an extension has been enabled/disabled in incognito. The
- // details are std::pair<Extension*, bool>, and the source is a Profile.
- EXTENSION_INCOGNITO_CHANGED,
-
// Sent when an extension is about to be installed so we can (in the case of
// themes) alert the user with a loading dialog. The source is the download
// manager and the details are the download url.