| 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/tab_helper.h" | 5 #include "chrome/browser/extensions/tab_helper.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 namespace extensions { | 76 namespace extensions { |
| 77 | 77 |
| 78 // A helper class to watch the progress of inline installation and update the | 78 // A helper class to watch the progress of inline installation and update the |
| 79 // renderer. Owned by the TabHelper. | 79 // renderer. Owned by the TabHelper. |
| 80 class TabHelper::InlineInstallObserver : public InstallObserver { | 80 class TabHelper::InlineInstallObserver : public InstallObserver { |
| 81 public: | 81 public: |
| 82 InlineInstallObserver(TabHelper* tab_helper, | 82 InlineInstallObserver(TabHelper* tab_helper, |
| 83 content::BrowserContext* browser_context, | 83 content::BrowserContext* browser_context, |
| 84 int routing_id, | 84 int routing_id, |
| 85 const std::string& extension_id, | 85 const ExtensionId& extension_id, |
| 86 bool observe_download_progress, | 86 bool observe_download_progress, |
| 87 bool observe_install_stage) | 87 bool observe_install_stage) |
| 88 : tab_helper_(tab_helper), | 88 : tab_helper_(tab_helper), |
| 89 routing_id_(routing_id), | 89 routing_id_(routing_id), |
| 90 extension_id_(extension_id), | 90 extension_id_(extension_id), |
| 91 observe_download_progress_(observe_download_progress), | 91 observe_download_progress_(observe_download_progress), |
| 92 observe_install_stage_(observe_install_stage), | 92 observe_install_stage_(observe_install_stage), |
| 93 install_observer_(this) { | 93 install_observer_(this) { |
| 94 DCHECK(tab_helper); | 94 DCHECK(tab_helper); |
| 95 DCHECK(observe_download_progress || observe_install_stage); | 95 DCHECK(observe_download_progress || observe_install_stage); |
| 96 InstallTracker* install_tracker = | 96 InstallTracker* install_tracker = |
| 97 InstallTrackerFactory::GetForBrowserContext(browser_context); | 97 InstallTrackerFactory::GetForBrowserContext(browser_context); |
| 98 if (install_tracker) | 98 if (install_tracker) |
| 99 install_observer_.Add(install_tracker); | 99 install_observer_.Add(install_tracker); |
| 100 } | 100 } |
| 101 ~InlineInstallObserver() override {} | 101 ~InlineInstallObserver() override {} |
| 102 | 102 |
| 103 private: | 103 private: |
| 104 // InstallObserver: | 104 // InstallObserver: |
| 105 void OnBeginExtensionDownload(const std::string& extension_id) override { | 105 void OnBeginExtensionDownload(const ExtensionId& extension_id) override { |
| 106 SendInstallStageChangedMessage(extension_id, | 106 SendInstallStageChangedMessage(extension_id, |
| 107 api::webstore::INSTALL_STAGE_DOWNLOADING); | 107 api::webstore::INSTALL_STAGE_DOWNLOADING); |
| 108 } | 108 } |
| 109 void OnDownloadProgress(const std::string& extension_id, | 109 void OnDownloadProgress(const ExtensionId& extension_id, |
| 110 int percent_downloaded) override { | 110 int percent_downloaded) override { |
| 111 if (observe_download_progress_ && extension_id == extension_id_) { | 111 if (observe_download_progress_ && extension_id == extension_id_) { |
| 112 tab_helper_->Send(new ExtensionMsg_InlineInstallDownloadProgress( | 112 tab_helper_->Send(new ExtensionMsg_InlineInstallDownloadProgress( |
| 113 routing_id_, percent_downloaded)); | 113 routing_id_, percent_downloaded)); |
| 114 } | 114 } |
| 115 } | 115 } |
| 116 void OnBeginCrxInstall(const std::string& extension_id) override { | 116 void OnBeginCrxInstall(const ExtensionId& extension_id) override { |
| 117 SendInstallStageChangedMessage(extension_id, | 117 SendInstallStageChangedMessage(extension_id, |
| 118 api::webstore::INSTALL_STAGE_INSTALLING); | 118 api::webstore::INSTALL_STAGE_INSTALLING); |
| 119 } | 119 } |
| 120 void OnShutdown() override { install_observer_.RemoveAll(); } | 120 void OnShutdown() override { install_observer_.RemoveAll(); } |
| 121 | 121 |
| 122 void SendInstallStageChangedMessage(const std::string& extension_id, | 122 void SendInstallStageChangedMessage(const ExtensionId& extension_id, |
| 123 api::webstore::InstallStage stage) { | 123 api::webstore::InstallStage stage) { |
| 124 if (observe_install_stage_ && extension_id == extension_id_) { | 124 if (observe_install_stage_ && extension_id == extension_id_) { |
| 125 tab_helper_->Send( | 125 tab_helper_->Send( |
| 126 new ExtensionMsg_InlineInstallStageChanged(routing_id_, stage)); | 126 new ExtensionMsg_InlineInstallStageChanged(routing_id_, stage)); |
| 127 } | 127 } |
| 128 } | 128 } |
| 129 | 129 |
| 130 // The owning TabHelper (guaranteed to be valid). | 130 // The owning TabHelper (guaranteed to be valid). |
| 131 TabHelper* const tab_helper_; | 131 TabHelper* const tab_helper_; |
| 132 | 132 |
| 133 // The routing id to use in sending IPC updates. | 133 // The routing id to use in sending IPC updates. |
| 134 int routing_id_; | 134 int routing_id_; |
| 135 | 135 |
| 136 // The id of the extension to observe. | 136 // The id of the extension to observe. |
| 137 std::string extension_id_; | 137 ExtensionId extension_id_; |
| 138 | 138 |
| 139 // Whether or not to observe download/install progress. | 139 // Whether or not to observe download/install progress. |
| 140 const bool observe_download_progress_; | 140 const bool observe_download_progress_; |
| 141 const bool observe_install_stage_; | 141 const bool observe_install_stage_; |
| 142 | 142 |
| 143 ScopedObserver<InstallTracker, InstallObserver> install_observer_; | 143 ScopedObserver<InstallTracker, InstallObserver> install_observer_; |
| 144 | 144 |
| 145 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver); | 145 DISALLOW_COPY_AND_ASSIGN(InlineInstallObserver); |
| 146 }; | 146 }; |
| 147 | 147 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 251 } | 251 } |
| 252 | 252 |
| 253 UpdateExtensionAppIcon(extension_app_); | 253 UpdateExtensionAppIcon(extension_app_); |
| 254 | 254 |
| 255 content::NotificationService::current()->Notify( | 255 content::NotificationService::current()->Notify( |
| 256 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, | 256 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, |
| 257 content::Source<TabHelper>(this), | 257 content::Source<TabHelper>(this), |
| 258 content::NotificationService::NoDetails()); | 258 content::NotificationService::NoDetails()); |
| 259 } | 259 } |
| 260 | 260 |
| 261 void TabHelper::SetExtensionAppById(const std::string& extension_app_id) { | 261 void TabHelper::SetExtensionAppById(const ExtensionId& extension_app_id) { |
| 262 const Extension* extension = GetExtension(extension_app_id); | 262 const Extension* extension = GetExtension(extension_app_id); |
| 263 if (extension) | 263 if (extension) |
| 264 SetExtensionApp(extension); | 264 SetExtensionApp(extension); |
| 265 } | 265 } |
| 266 | 266 |
| 267 void TabHelper::SetExtensionAppIconById(const std::string& extension_app_id) { | 267 void TabHelper::SetExtensionAppIconById(const ExtensionId& extension_app_id) { |
| 268 const Extension* extension = GetExtension(extension_app_id); | 268 const Extension* extension = GetExtension(extension_app_id); |
| 269 if (extension) | 269 if (extension) |
| 270 UpdateExtensionAppIcon(extension); | 270 UpdateExtensionAppIcon(extension); |
| 271 } | 271 } |
| 272 | 272 |
| 273 SkBitmap* TabHelper::GetExtensionAppIcon() { | 273 SkBitmap* TabHelper::GetExtensionAppIcon() { |
| 274 if (extension_app_icon_.empty()) | 274 if (extension_app_icon_.empty()) |
| 275 return NULL; | 275 return NULL; |
| 276 | 276 |
| 277 return &extension_app_icon_; | 277 return &extension_app_icon_; |
| (...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 523 void TabHelper::OnContentScriptsExecuting( | 523 void TabHelper::OnContentScriptsExecuting( |
| 524 content::RenderFrameHost* host, | 524 content::RenderFrameHost* host, |
| 525 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, | 525 const ScriptExecutionObserver::ExecutingScriptsMap& executing_scripts_map, |
| 526 const GURL& on_url) { | 526 const GURL& on_url) { |
| 527 FOR_EACH_OBSERVER( | 527 FOR_EACH_OBSERVER( |
| 528 ScriptExecutionObserver, | 528 ScriptExecutionObserver, |
| 529 script_execution_observers_, | 529 script_execution_observers_, |
| 530 OnScriptsExecuted(web_contents(), executing_scripts_map, on_url)); | 530 OnScriptsExecuted(web_contents(), executing_scripts_map, on_url)); |
| 531 } | 531 } |
| 532 | 532 |
| 533 const Extension* TabHelper::GetExtension(const std::string& extension_app_id) { | 533 const Extension* TabHelper::GetExtension(const ExtensionId& extension_app_id) { |
| 534 if (extension_app_id.empty()) | 534 if (extension_app_id.empty()) |
| 535 return NULL; | 535 return NULL; |
| 536 | 536 |
| 537 content::BrowserContext* context = web_contents()->GetBrowserContext(); | 537 content::BrowserContext* context = web_contents()->GetBrowserContext(); |
| 538 return ExtensionRegistry::Get(context)->enabled_extensions().GetByID( | 538 return ExtensionRegistry::Get(context)->enabled_extensions().GetByID( |
| 539 extension_app_id); | 539 extension_app_id); |
| 540 } | 540 } |
| 541 | 541 |
| 542 void TabHelper::UpdateExtensionAppIcon(const Extension* extension) { | 542 void TabHelper::UpdateExtensionAppIcon(const Extension* extension) { |
| 543 extension_app_icon_.reset(); | 543 extension_app_icon_.reset(); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); | 575 web_contents()->NotifyNavigationStateChanged(content::INVALIDATE_TYPE_TAB); |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 | 578 |
| 579 WindowController* TabHelper::GetExtensionWindowController() const { | 579 WindowController* TabHelper::GetExtensionWindowController() const { |
| 580 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); | 580 return ExtensionTabUtil::GetWindowControllerOfTab(web_contents()); |
| 581 } | 581 } |
| 582 | 582 |
| 583 void TabHelper::OnReenableComplete(int install_id, | 583 void TabHelper::OnReenableComplete(int install_id, |
| 584 int return_route_id, | 584 int return_route_id, |
| 585 const std::string& extension_id, | 585 const ExtensionId& extension_id, |
| 586 ExtensionReenabler::ReenableResult result) { | 586 ExtensionReenabler::ReenableResult result) { |
| 587 // Map the re-enable results to webstore-install results. | 587 // Map the re-enable results to webstore-install results. |
| 588 webstore_install::Result webstore_result = webstore_install::SUCCESS; | 588 webstore_install::Result webstore_result = webstore_install::SUCCESS; |
| 589 std::string error; | 589 std::string error; |
| 590 switch (result) { | 590 switch (result) { |
| 591 case ExtensionReenabler::REENABLE_SUCCESS: | 591 case ExtensionReenabler::REENABLE_SUCCESS: |
| 592 break; // already set | 592 break; // already set |
| 593 case ExtensionReenabler::USER_CANCELED: | 593 case ExtensionReenabler::USER_CANCELED: |
| 594 webstore_result = webstore_install::USER_CANCELLED; | 594 webstore_result = webstore_install::USER_CANCELLED; |
| 595 error = "User canceled install."; | 595 error = "User canceled install."; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 607 OnInlineInstallComplete(install_id, return_route_id, extension_id, | 607 OnInlineInstallComplete(install_id, return_route_id, extension_id, |
| 608 result == ExtensionReenabler::REENABLE_SUCCESS, error, | 608 result == ExtensionReenabler::REENABLE_SUCCESS, error, |
| 609 webstore_result); | 609 webstore_result); |
| 610 // Note: ExtensionReenabler contained the callback with the curried-in | 610 // Note: ExtensionReenabler contained the callback with the curried-in |
| 611 // |extension_id|; delete it last. | 611 // |extension_id|; delete it last. |
| 612 extension_reenabler_.reset(); | 612 extension_reenabler_.reset(); |
| 613 } | 613 } |
| 614 | 614 |
| 615 void TabHelper::OnInlineInstallComplete(int install_id, | 615 void TabHelper::OnInlineInstallComplete(int install_id, |
| 616 int return_route_id, | 616 int return_route_id, |
| 617 const std::string& extension_id, | 617 const ExtensionId& extension_id, |
| 618 bool success, | 618 bool success, |
| 619 const std::string& error, | 619 const std::string& error, |
| 620 webstore_install::Result result) { | 620 webstore_install::Result result) { |
| 621 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id)); | 621 DCHECK_EQ(1u, pending_inline_installations_.count(extension_id)); |
| 622 pending_inline_installations_.erase(extension_id); | 622 pending_inline_installations_.erase(extension_id); |
| 623 install_observers_.erase(extension_id); | 623 install_observers_.erase(extension_id); |
| 624 Send(new ExtensionMsg_InlineWebstoreInstallResponse( | 624 Send(new ExtensionMsg_InlineWebstoreInstallResponse( |
| 625 return_route_id, | 625 return_route_id, |
| 626 install_id, | 626 install_id, |
| 627 success, | 627 success, |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 673 } | 673 } |
| 674 } | 674 } |
| 675 | 675 |
| 676 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { | 676 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { |
| 677 render_frame_host->Send( | 677 render_frame_host->Send( |
| 678 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), | 678 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), |
| 679 SessionTabHelper::IdForTab(web_contents()))); | 679 SessionTabHelper::IdForTab(web_contents()))); |
| 680 } | 680 } |
| 681 | 681 |
| 682 } // namespace extensions | 682 } // namespace extensions |
| OLD | NEW |