Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(355)

Side by Side Diff: chrome/browser/extensions/user_script_master.cc

Issue 567037: Initial work on making extensions work in incognito mode. (Closed)
Patch Set: added experimental requirement Created 10 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/extensions/user_script_master.h" 5 #include "chrome/browser/extensions/user_script_master.h"
6 6
7 #include <string> 7 #include <string>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/file_path.h" 10 #include "base/file_path.h"
11 #include "base/file_util.h" 11 #include "base/file_util.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/pickle.h" 13 #include "base/pickle.h"
14 #include "base/stl_util-inl.h" 14 #include "base/stl_util-inl.h"
15 #include "base/string_util.h" 15 #include "base/string_util.h"
16 #include "base/thread.h" 16 #include "base/thread.h"
17 #include "chrome/browser/browser_process.h" 17 #include "chrome/browser/browser_process.h"
18 #include "chrome/browser/extensions/extensions_service.h" 18 #include "chrome/browser/extensions/extensions_service.h"
19 #include "chrome/browser/profile.h"
19 #include "chrome/common/extensions/extension.h" 20 #include "chrome/common/extensions/extension.h"
20 #include "chrome/common/notification_service.h" 21 #include "chrome/common/notification_service.h"
21 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
22 #include "net/base/net_util.h" 23 #include "net/base/net_util.h"
23 24
24 25
25 // Helper function to parse greasesmonkey headers 26 // Helper function to parse greasesmonkey headers
26 static bool GetDeclarationValue(const base::StringPiece& line, 27 static bool GetDeclarationValue(const base::StringPiece& line,
27 const base::StringPiece& prefix, 28 const base::StringPiece& prefix,
28 std::string* value) { 29 std::string* value) {
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 327
327 void UserScriptMaster::Observe(NotificationType type, 328 void UserScriptMaster::Observe(NotificationType type,
328 const NotificationSource& source, 329 const NotificationSource& source,
329 const NotificationDetails& details) { 330 const NotificationDetails& details) {
330 switch (type.value) { 331 switch (type.value) {
331 case NotificationType::EXTENSIONS_READY: 332 case NotificationType::EXTENSIONS_READY:
332 extensions_service_ready_ = true; 333 extensions_service_ready_ = true;
333 StartScan(); 334 StartScan();
334 break; 335 break;
335 case NotificationType::EXTENSION_LOADED: { 336 case NotificationType::EXTENSION_LOADED: {
336 // TODO(aa): Fix race here. A page could need a content script on startup,
337 // before the extension has loaded. We need to freeze the renderer in
338 // that case.
339 // See: http://code.google.com/p/chromium/issues/detail?id=11547.
340
341 // Add any content scripts inside the extension. 337 // Add any content scripts inside the extension.
342 Extension* extension = Details<Extension>(details).ptr(); 338 Extension* extension = Details<Extension>(details).ptr();
339 bool incognito_enabled = profile_->GetExtensionsService()->
340 IsIncognitoEnabled(extension->id());
343 const UserScriptList& scripts = extension->content_scripts(); 341 const UserScriptList& scripts = extension->content_scripts();
344 for (UserScriptList::const_iterator iter = scripts.begin(); 342 for (UserScriptList::const_iterator iter = scripts.begin();
345 iter != scripts.end(); ++iter) { 343 iter != scripts.end(); ++iter) {
346 lone_scripts_.push_back(*iter); 344 lone_scripts_.push_back(*iter);
345 lone_scripts_.back().set_incognito_enabled(incognito_enabled);
347 } 346 }
348 if (extensions_service_ready_) 347 if (extensions_service_ready_)
349 StartScan(); 348 StartScan();
350 break; 349 break;
351 } 350 }
352 351
353 case NotificationType::EXTENSION_UNLOADED: { 352 case NotificationType::EXTENSION_UNLOADED: {
354 // Remove any content scripts. 353 // Remove any content scripts.
355 Extension* extension = Details<Extension>(details).ptr(); 354 Extension* extension = Details<Extension>(details).ptr();
356 UserScriptList new_lone_scripts; 355 UserScriptList new_lone_scripts;
(...skipping 15 matching lines...) Expand all
372 DCHECK(false); 371 DCHECK(false);
373 } 372 }
374 } 373 }
375 374
376 void UserScriptMaster::StartScan() { 375 void UserScriptMaster::StartScan() {
377 if (!script_reloader_) 376 if (!script_reloader_)
378 script_reloader_ = new ScriptReloader(this); 377 script_reloader_ = new ScriptReloader(this);
379 378
380 script_reloader_->StartScan(user_script_dir_, lone_scripts_); 379 script_reloader_->StartScan(user_script_dir_, lone_scripts_);
381 } 380 }
381
382 void UserScriptMaster::ReloadExtensionForTesting(Extension* extension) {
383 bool incognito_enabled = profile_->GetExtensionsService()->
384 IsIncognitoEnabled(extension->id());
385 for (UserScriptList::iterator iter = lone_scripts_.begin();
386 iter != lone_scripts_.end(); ++iter) {
387 if (iter->extension_id() == extension->id())
388 (*iter).set_incognito_enabled(incognito_enabled);
389 }
390 StartScan();
391 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/user_script_master.h ('k') | chrome/browser/gtk/browser_actions_toolbar_gtk.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698