summaryrefslogtreecommitdiffstats
path: root/chrome/browser/views
diff options
context:
space:
mode:
authormpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-11 23:25:21 +0000
committermpcomplete@chromium.org <mpcomplete@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-11 23:25:21 +0000
commit55a356908083c25a2829db1636564c50c57b430f (patch)
tree1fa448b284205c57f594ca34b175db202af1aec1 /chrome/browser/views
parent6149d3e3ba96cc4aac419777094a1e090b0825e9 (diff)
downloadchromium_src-55a356908083c25a2829db1636564c50c57b430f.zip
chromium_src-55a356908083c25a2829db1636564c50c57b430f.tar.gz
chromium_src-55a356908083c25a2829db1636564c50c57b430f.tar.bz2
Initial work on making extensions work in incognito mode.
This merely adds a way to enable content scripts and browser actions in incognito windows. They still don't work properly because none of the APIs work with incognito tabs. The way to enable an extension is to add an "incognito" bit in the user prefs file. My plan is to add UI for this later. BUG=32365 Review URL: http://codereview.chromium.org/567037 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38852 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/views')
-rw-r--r--chrome/browser/views/browser_actions_container.cc26
-rw-r--r--chrome/browser/views/browser_actions_container.h9
2 files changed, 34 insertions, 1 deletions
diff --git a/chrome/browser/views/browser_actions_container.cc b/chrome/browser/views/browser_actions_container.cc
index d089a40..5a1ae90 100644
--- a/chrome/browser/views/browser_actions_container.cc
+++ b/chrome/browser/views/browser_actions_container.cc
@@ -450,6 +450,9 @@ void BrowserActionsContainer::CreateBrowserActionViews() {
DCHECK(browser_action_views_.empty());
for (ExtensionList::iterator iter = model_->begin();
iter != model_->end(); ++iter) {
+ if (!ShouldDisplayBrowserAction(*iter))
+ continue;
+
BrowserActionView* view = new BrowserActionView(*iter, this);
browser_action_views_.push_back(view);
AddChildView(view);
@@ -673,6 +676,7 @@ void BrowserActionsContainer::ViewHierarchyChanged(bool is_add,
bool BrowserActionsContainer::GetDropFormats(
int* formats, std::set<OSExchangeData::CustomFormat>* custom_formats) {
custom_formats->insert(BrowserActionDragData::GetBrowserActionCustomFormat());
+
return true;
}
@@ -771,6 +775,9 @@ int BrowserActionsContainer::OnPerformDrop(
if (i > data.index())
--i;
+ if (profile_->IsOffTheRecord())
+ i = model_->IncognitoIndexToOriginal(i);
+
model_->MoveBrowserAction(dragging, i);
OnDragExited(); // Perform clean up after dragging.
@@ -933,6 +940,12 @@ void BrowserActionsContainer::BrowserActionAdded(Extension* extension,
CloseMenus();
+ if (!ShouldDisplayBrowserAction(extension))
+ return;
+
+ if (profile_->IsOffTheRecord())
+ index = model_->OriginalIndexToIncognito(index);
+
// Before we change anything, determine the number of visible browser actions.
size_t visible_actions = VisibleBrowserActions();
@@ -1011,6 +1024,12 @@ void BrowserActionsContainer::BrowserActionRemoved(Extension* extension) {
void BrowserActionsContainer::BrowserActionMoved(Extension* extension,
int index) {
+ if (!ShouldDisplayBrowserAction(extension))
+ return;
+
+ if (profile_->IsOffTheRecord())
+ index = model_->OriginalIndexToIncognito(index);
+
DCHECK(index >= 0 && index < static_cast<int>(browser_action_views_.size()));
DeleteBrowserActionViews();
@@ -1104,3 +1123,10 @@ void BrowserActionsContainer::NotifyMenuDeleted(
DCHECK(controller == overflow_menu_);
overflow_menu_ = NULL;
}
+
+bool BrowserActionsContainer::ShouldDisplayBrowserAction(Extension* extension) {
+ // Only display incognito-enabled extensions while in incognito mode.
+ return (!profile_->IsOffTheRecord() ||
+ profile_->GetExtensionsService()->
+ IsIncognitoEnabled(extension->id()));
+}
diff --git a/chrome/browser/views/browser_actions_container.h b/chrome/browser/views/browser_actions_container.h
index a7a5b59ac..1ace12d 100644
--- a/chrome/browser/views/browser_actions_container.h
+++ b/chrome/browser/views/browser_actions_container.h
@@ -399,7 +399,14 @@ class BrowserActionsContainer
// all the padding that we normally show if there are icons.
int ContainerMinSize() const;
- // The vector of browser actions (icons/image buttons for each action).
+ // Returns true if this extension should be shown in this toolbar. This can
+ // return false if we are in an incognito window and the extension is disabled
+ // for incognito.
+ bool ShouldDisplayBrowserAction(Extension* extension);
+
+ // The vector of browser actions (icons/image buttons for each action). Note
+ // that not every BrowserAction in the ToolbarModel will necessarily be in
+ // this collection. Some extensions may be disabled in incognito windows.
BrowserActionViews browser_action_views_;
NotificationRegistrar registrar_;