| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/api/extension_action/extension_action_api.h" | 5 #include "chrome/browser/extensions/api/extension_action/extension_action_api.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/lazy_instance.h" | 8 #include "base/lazy_instance.h" |
| 9 #include "base/strings/string_number_conversions.h" | 9 #include "base/strings/string_number_conversions.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| 11 #include "base/values.h" | 11 #include "base/values.h" |
| 12 #include "chrome/browser/extensions/active_script_controller.h" | 12 #include "chrome/browser/extensions/active_script_controller.h" |
| 13 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" | 13 #include "chrome/browser/extensions/api/extension_action/extension_page_actions_
api_constants.h" |
| 14 #include "chrome/browser/extensions/extension_action.h" | 14 #include "chrome/browser/extensions/extension_action.h" |
| 15 #include "chrome/browser/extensions/extension_action_manager.h" | 15 #include "chrome/browser/extensions/extension_action_manager.h" |
| 16 #include "chrome/browser/extensions/extension_tab_util.h" | 16 #include "chrome/browser/extensions/extension_tab_util.h" |
| 17 #include "chrome/browser/extensions/extension_toolbar_model.h" | 17 #include "chrome/browser/extensions/extension_toolbar_model.h" |
| 18 #include "chrome/browser/extensions/tab_helper.h" | 18 #include "chrome/browser/extensions/tab_helper.h" |
| 19 #include "chrome/browser/profiles/profile.h" | 19 #include "chrome/browser/profiles/profile.h" |
| 20 #include "chrome/browser/sessions/session_tab_helper.h" | 20 #include "chrome/browser/sessions/session_tab_helper.h" |
| 21 #include "chrome/browser/ui/browser.h" | 21 #include "chrome/browser/ui/browser.h" |
| 22 #include "chrome/browser/ui/browser_finder.h" |
| 23 #include "chrome/browser/ui/browser_window.h" |
| 24 #include "chrome/browser/ui/location_bar/location_bar.h" |
| 22 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 25 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 23 #include "chrome/common/extensions/api/extension_action/action_info.h" | 26 #include "chrome/common/extensions/api/extension_action/action_info.h" |
| 24 #include "chrome/common/render_messages.h" | 27 #include "chrome/common/render_messages.h" |
| 25 #include "content/public/browser/navigation_entry.h" | 28 #include "content/public/browser/navigation_entry.h" |
| 26 #include "content/public/browser/notification_service.h" | 29 #include "content/public/browser/notification_service.h" |
| 27 #include "extensions/browser/event_router.h" | 30 #include "extensions/browser/event_router.h" |
| 28 #include "extensions/browser/extension_function_registry.h" | 31 #include "extensions/browser/extension_function_registry.h" |
| 29 #include "extensions/browser/extension_host.h" | 32 #include "extensions/browser/extension_host.h" |
| 30 #include "extensions/browser/extension_registry.h" | 33 #include "extensions/browser/extension_registry.h" |
| 31 #include "extensions/browser/extension_system.h" | 34 #include "extensions/browser/extension_system.h" |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 225 } | 228 } |
| 226 } | 229 } |
| 227 dict->Set(kIconStorageKey, icon_value); | 230 dict->Set(kIconStorageKey, icon_value); |
| 228 } | 231 } |
| 229 return dict.Pass(); | 232 return dict.Pass(); |
| 230 } | 233 } |
| 231 | 234 |
| 232 } // namespace | 235 } // namespace |
| 233 | 236 |
| 234 // | 237 // |
| 238 // ExtensionActionAPI::Observer |
| 239 // |
| 240 |
| 241 void ExtensionActionAPI::Observer::OnExtensionActionUpdated( |
| 242 ExtensionAction* extension_action, |
| 243 content::WebContents* web_contents, |
| 244 content::BrowserContext* browser_context) { |
| 245 } |
| 246 |
| 247 void ExtensionActionAPI::Observer::OnPageActionsUpdated( |
| 248 content::WebContents* web_contents) { |
| 249 } |
| 250 |
| 251 void ExtensionActionAPI::Observer::OnExtensionActionAPIShuttingDown() { |
| 252 } |
| 253 |
| 254 ExtensionActionAPI::Observer::~Observer() { |
| 255 } |
| 256 |
| 257 // |
| 235 // ExtensionActionAPI | 258 // ExtensionActionAPI |
| 236 // | 259 // |
| 237 | 260 |
| 238 static base::LazyInstance<BrowserContextKeyedAPIFactory<ExtensionActionAPI> > | 261 static base::LazyInstance<BrowserContextKeyedAPIFactory<ExtensionActionAPI> > |
| 239 g_factory = LAZY_INSTANCE_INITIALIZER; | 262 g_factory = LAZY_INSTANCE_INITIALIZER; |
| 240 | 263 |
| 241 ExtensionActionAPI::ExtensionActionAPI(content::BrowserContext* context) | 264 ExtensionActionAPI::ExtensionActionAPI(content::BrowserContext* context) |
| 242 : browser_context_(context) { | 265 : browser_context_(context) { |
| 243 ExtensionFunctionRegistry* registry = | 266 ExtensionFunctionRegistry* registry = |
| 244 ExtensionFunctionRegistry::GetInstance(); | 267 ExtensionFunctionRegistry::GetInstance(); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 return ExtensionAction::ACTION_NONE; | 387 return ExtensionAction::ACTION_NONE; |
| 365 } | 388 } |
| 366 | 389 |
| 367 void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, | 390 void ExtensionActionAPI::NotifyChange(ExtensionAction* extension_action, |
| 368 content::WebContents* web_contents, | 391 content::WebContents* web_contents, |
| 369 content::BrowserContext* context) { | 392 content::BrowserContext* context) { |
| 370 FOR_EACH_OBSERVER( | 393 FOR_EACH_OBSERVER( |
| 371 Observer, | 394 Observer, |
| 372 observers_, | 395 observers_, |
| 373 OnExtensionActionUpdated(extension_action, web_contents, context)); | 396 OnExtensionActionUpdated(extension_action, web_contents, context)); |
| 397 |
| 398 if (extension_action->action_type() == ActionInfo::TYPE_PAGE) |
| 399 NotifyPageActionsChanged(web_contents); |
| 374 } | 400 } |
| 375 | 401 |
| 376 void ExtensionActionAPI::ClearAllValuesForTab( | 402 void ExtensionActionAPI::ClearAllValuesForTab( |
| 377 content::WebContents* web_contents) { | 403 content::WebContents* web_contents) { |
| 378 DCHECK(web_contents); | 404 DCHECK(web_contents); |
| 379 int tab_id = SessionTabHelper::IdForTab(web_contents); | 405 int tab_id = SessionTabHelper::IdForTab(web_contents); |
| 380 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); | 406 content::BrowserContext* browser_context = web_contents->GetBrowserContext(); |
| 381 const ExtensionSet& enabled_extensions = | 407 const ExtensionSet& enabled_extensions = |
| 382 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); | 408 ExtensionRegistry::Get(browser_context_)->enabled_extensions(); |
| 383 ExtensionActionManager* action_manager = | 409 ExtensionActionManager* action_manager = |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 434 args->Append(tab_value); | 460 args->Append(tab_value); |
| 435 | 461 |
| 436 DispatchEventToExtension( | 462 DispatchEventToExtension( |
| 437 web_contents->GetBrowserContext(), | 463 web_contents->GetBrowserContext(), |
| 438 extension_action.extension_id(), | 464 extension_action.extension_id(), |
| 439 event_name, | 465 event_name, |
| 440 args.Pass()); | 466 args.Pass()); |
| 441 } | 467 } |
| 442 } | 468 } |
| 443 | 469 |
| 470 void ExtensionActionAPI::NotifyPageActionsChanged( |
| 471 content::WebContents* web_contents) { |
| 472 Browser* browser = chrome::FindBrowserWithWebContents(web_contents); |
| 473 if (!browser) |
| 474 return; |
| 475 LocationBar* location_bar = |
| 476 browser->window() ? browser->window()->GetLocationBar() : NULL; |
| 477 if (!location_bar) |
| 478 return; |
| 479 location_bar->UpdatePageActions(); |
| 480 |
| 481 FOR_EACH_OBSERVER(Observer, observers_, OnPageActionsUpdated(web_contents)); |
| 482 } |
| 483 |
| 444 void ExtensionActionAPI::Shutdown() { | 484 void ExtensionActionAPI::Shutdown() { |
| 445 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionActionAPIShuttingDown()); | 485 FOR_EACH_OBSERVER(Observer, observers_, OnExtensionActionAPIShuttingDown()); |
| 446 } | 486 } |
| 447 | 487 |
| 448 // | 488 // |
| 449 // ExtensionActionStorageManager | 489 // ExtensionActionStorageManager |
| 450 // | 490 // |
| 451 | 491 |
| 452 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile) | 492 ExtensionActionStorageManager::ExtensionActionStorageManager(Profile* profile) |
| 453 : profile_(profile), | 493 : profile_(profile), |
| (...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 841 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || | 881 if (host->extension_host_type() != VIEW_TYPE_EXTENSION_POPUP || |
| 842 host->extension()->id() != extension_->id()) | 882 host->extension()->id() != extension_->id()) |
| 843 return; | 883 return; |
| 844 | 884 |
| 845 SendResponse(true); | 885 SendResponse(true); |
| 846 response_sent_ = true; | 886 response_sent_ = true; |
| 847 registrar_.RemoveAll(); | 887 registrar_.RemoveAll(); |
| 848 } | 888 } |
| 849 | 889 |
| 850 } // namespace extensions | 890 } // namespace extensions |
| OLD | NEW |