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

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

Issue 2037873002: [Extensions] Observe unloading extensions in the TabHelper (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Istiaque's Created 4 years, 6 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) 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 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), 77 profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())),
78 extension_app_(NULL), 78 extension_app_(NULL),
79 pending_web_app_action_(NONE), 79 pending_web_app_action_(NONE),
80 last_committed_nav_entry_unique_id_(0), 80 last_committed_nav_entry_unique_id_(0),
81 update_shortcut_on_load_complete_(false), 81 update_shortcut_on_load_complete_(false),
82 script_executor_( 82 script_executor_(
83 new ScriptExecutor(web_contents, &script_execution_observers_)), 83 new ScriptExecutor(web_contents, &script_execution_observers_)),
84 location_bar_controller_(new LocationBarController(web_contents)), 84 location_bar_controller_(new LocationBarController(web_contents)),
85 extension_action_runner_(new ExtensionActionRunner(web_contents)), 85 extension_action_runner_(new ExtensionActionRunner(web_contents)),
86 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()), 86 webstore_inline_installer_factory_(new WebstoreInlineInstallerFactory()),
87 registry_observer_(this),
87 image_loader_ptr_factory_(this), 88 image_loader_ptr_factory_(this),
88 weak_ptr_factory_(this) { 89 weak_ptr_factory_(this) {
89 // The ActiveTabPermissionManager requires a session ID; ensure this 90 // The ActiveTabPermissionManager requires a session ID; ensure this
90 // WebContents has one. 91 // WebContents has one.
91 SessionTabHelper::CreateForWebContents(web_contents); 92 SessionTabHelper::CreateForWebContents(web_contents);
92 // The Unretained() is safe because ForEachFrame is synchronous. 93 // The Unretained() is safe because ForEachFrame is synchronous.
93 web_contents->ForEachFrame( 94 web_contents->ForEachFrame(
94 base::Bind(&TabHelper::SetTabId, base::Unretained(this))); 95 base::Bind(&TabHelper::SetTabId, base::Unretained(this)));
95 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter( 96 active_tab_permission_granter_.reset(new ActiveTabPermissionGranter(
96 web_contents, 97 web_contents,
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 script_execution_observers_.RemoveObserver(observer); 163 script_execution_observers_.RemoveObserver(observer);
163 } 164 }
164 165
165 void TabHelper::SetExtensionApp(const Extension* extension) { 166 void TabHelper::SetExtensionApp(const Extension* extension) {
166 DCHECK(!extension || AppLaunchInfo::GetFullLaunchURL(extension).is_valid()); 167 DCHECK(!extension || AppLaunchInfo::GetFullLaunchURL(extension).is_valid());
167 if (extension_app_ == extension) 168 if (extension_app_ == extension)
168 return; 169 return;
169 170
170 extension_app_ = extension; 171 extension_app_ = extension;
171 172
173 if (extension_app_) {
174 registry_observer_.Add(
175 ExtensionRegistry::Get(web_contents()->GetBrowserContext()));
176 } else {
177 registry_observer_.RemoveAll();
178 }
179
172 UpdateExtensionAppIcon(extension_app_); 180 UpdateExtensionAppIcon(extension_app_);
173 181
174 content::NotificationService::current()->Notify( 182 content::NotificationService::current()->Notify(
175 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED, 183 chrome::NOTIFICATION_TAB_CONTENTS_APPLICATION_EXTENSION_CHANGED,
176 content::Source<TabHelper>(this), 184 content::Source<TabHelper>(this),
177 content::NotificationService::NoDetails()); 185 content::NotificationService::NoDetails());
178 } 186 }
179 187
180 void TabHelper::SetExtensionAppById(const std::string& extension_app_id) { 188 void TabHelper::SetExtensionAppById(const std::string& extension_app_id) {
181 const Extension* extension = GetExtension(extension_app_id); 189 const Extension* extension = GetExtension(extension_app_id);
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
525 install_id, 533 install_id,
526 success, 534 success,
527 success ? std::string() : error, 535 success ? std::string() : error,
528 result)); 536 result));
529 } 537 }
530 538
531 WebContents* TabHelper::GetAssociatedWebContents() const { 539 WebContents* TabHelper::GetAssociatedWebContents() const {
532 return web_contents(); 540 return web_contents();
533 } 541 }
534 542
543 void TabHelper::OnExtensionUnloaded(
544 content::BrowserContext* browser_context,
545 const Extension* extension,
546 UnloadedExtensionInfo::Reason reason) {
547 DCHECK(extension_app_);
548 if (extension == extension_app_)
549 SetExtensionApp(nullptr);
550 }
551
535 void TabHelper::GetApplicationInfo(WebAppAction action) { 552 void TabHelper::GetApplicationInfo(WebAppAction action) {
536 NavigationEntry* entry = 553 NavigationEntry* entry =
537 web_contents()->GetController().GetLastCommittedEntry(); 554 web_contents()->GetController().GetLastCommittedEntry();
538 if (!entry) 555 if (!entry)
539 return; 556 return;
540 557
541 pending_web_app_action_ = action; 558 pending_web_app_action_ = action;
542 last_committed_nav_entry_unique_id_ = entry->GetUniqueID(); 559 last_committed_nav_entry_unique_id_ = entry->GetUniqueID();
543 560
544 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id())); 561 Send(new ChromeViewMsg_GetWebApplicationInfo(routing_id()));
(...skipping 18 matching lines...) Expand all
563 } 580 }
564 } 581 }
565 582
566 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) { 583 void TabHelper::SetTabId(content::RenderFrameHost* render_frame_host) {
567 render_frame_host->Send( 584 render_frame_host->Send(
568 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(), 585 new ExtensionMsg_SetTabId(render_frame_host->GetRoutingID(),
569 SessionTabHelper::IdForTab(web_contents()))); 586 SessionTabHelper::IdForTab(web_contents())));
570 } 587 }
571 588
572 } // namespace extensions 589 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/tab_helper.h ('k') | chrome/browser/extensions/tab_helper_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698