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

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

Issue 8983012: Get rid of content::NavigationController in cc file and use "using" instead. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 11 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/extension_navigation_observer.h" 5 #include "chrome/browser/extensions/extension_navigation_observer.h"
6 6
7 #include "chrome/browser/extensions/extension_service.h" 7 #include "chrome/browser/extensions/extension_service.h"
8 #include "chrome/browser/profiles/profile.h" 8 #include "chrome/browser/profiles/profile.h"
9 #include "content/public/browser/navigation_controller.h" 9 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/browser/navigation_entry.h" 10 #include "content/public/browser/navigation_entry.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 12
13 using content::NavigationController;
13 using content::NavigationEntry; 14 using content::NavigationEntry;
14 15
15 ExtensionNavigationObserver::ExtensionNavigationObserver(Profile* profile) 16 ExtensionNavigationObserver::ExtensionNavigationObserver(Profile* profile)
16 : profile_(profile) { 17 : profile_(profile) {
17 RegisterForNotifications(); 18 RegisterForNotifications();
18 } 19 }
19 20
20 ExtensionNavigationObserver::~ExtensionNavigationObserver() {} 21 ExtensionNavigationObserver::~ExtensionNavigationObserver() {}
21 22
22 void ExtensionNavigationObserver::Observe( 23 void ExtensionNavigationObserver::Observe(
23 int type, 24 int type,
24 const content::NotificationSource& source, 25 const content::NotificationSource& source,
25 const content::NotificationDetails& details) { 26 const content::NotificationDetails& details) {
26 if (type != content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 27 if (type != content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
27 NOTREACHED(); 28 NOTREACHED();
28 return; 29 return;
29 } 30 }
30 31
31 content::NavigationController* controller = 32 NavigationController* controller =
32 content::Source<content::NavigationController>(source).ptr(); 33 content::Source<NavigationController>(source).ptr();
33 if (!profile_->IsSameProfile( 34 if (!profile_->IsSameProfile(
34 Profile::FromBrowserContext(controller->GetBrowserContext()))) 35 Profile::FromBrowserContext(controller->GetBrowserContext())))
35 return; 36 return;
36 37
37 PromptToEnableExtensionIfNecessary(controller); 38 PromptToEnableExtensionIfNecessary(controller);
38 } 39 }
39 40
40 void ExtensionNavigationObserver::RegisterForNotifications() { 41 void ExtensionNavigationObserver::RegisterForNotifications() {
41 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 42 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
42 content::NotificationService::AllSources()); 43 content::NotificationService::AllSources());
43 } 44 }
44 45
45 void ExtensionNavigationObserver::PromptToEnableExtensionIfNecessary( 46 void ExtensionNavigationObserver::PromptToEnableExtensionIfNecessary(
46 content::NavigationController* nav_controller) { 47 NavigationController* nav_controller) {
47 // Bail out if we're already running a prompt. 48 // Bail out if we're already running a prompt.
48 if (!in_progress_prompt_extension_id_.empty()) 49 if (!in_progress_prompt_extension_id_.empty())
49 return; 50 return;
50 51
51 NavigationEntry* nav_entry = nav_controller->GetActiveEntry(); 52 NavigationEntry* nav_entry = nav_controller->GetActiveEntry();
52 if (!nav_entry) 53 if (!nav_entry)
53 return; 54 return;
54 55
55 ExtensionService* extension_service = profile_->GetExtensionService(); 56 ExtensionService* extension_service = profile_->GetExtensionService();
56 const Extension* extension = 57 const Extension* extension =
(...skipping 16 matching lines...) Expand all
73 74
74 extension_install_ui_.reset(new ExtensionInstallUI(profile_)); 75 extension_install_ui_.reset(new ExtensionInstallUI(profile_));
75 extension_install_ui_->ConfirmReEnable(this, extension); 76 extension_install_ui_->ConfirmReEnable(this, extension);
76 } 77 }
77 } 78 }
78 79
79 void ExtensionNavigationObserver::InstallUIProceed() { 80 void ExtensionNavigationObserver::InstallUIProceed() {
80 ExtensionService* extension_service = profile_->GetExtensionService(); 81 ExtensionService* extension_service = profile_->GetExtensionService();
81 const Extension* extension = extension_service->GetExtensionById( 82 const Extension* extension = extension_service->GetExtensionById(
82 in_progress_prompt_extension_id_, true); 83 in_progress_prompt_extension_id_, true);
83 content::NavigationController* nav_controller = 84 NavigationController* nav_controller =
84 in_progress_prompt_navigation_controller_; 85 in_progress_prompt_navigation_controller_;
85 CHECK(extension); 86 CHECK(extension);
86 CHECK(nav_controller); 87 CHECK(nav_controller);
87 88
88 in_progress_prompt_extension_id_ = ""; 89 in_progress_prompt_extension_id_ = "";
89 in_progress_prompt_navigation_controller_ = NULL; 90 in_progress_prompt_navigation_controller_ = NULL;
90 extension_install_ui_.reset(); 91 extension_install_ui_.reset();
91 92
92 // Grant permissions, re-enable the extension, and then reload the tab. 93 // Grant permissions, re-enable the extension, and then reload the tab.
93 extension_service->GrantPermissionsAndEnableExtension(extension); 94 extension_service->GrantPermissionsAndEnableExtension(extension);
94 nav_controller->Reload(true); 95 nav_controller->Reload(true);
95 } 96 }
96 97
97 void ExtensionNavigationObserver::InstallUIAbort(bool user_initiated) { 98 void ExtensionNavigationObserver::InstallUIAbort(bool user_initiated) {
98 ExtensionService* extension_service = profile_->GetExtensionService(); 99 ExtensionService* extension_service = profile_->GetExtensionService();
99 const Extension* extension = extension_service->GetExtensionById( 100 const Extension* extension = extension_service->GetExtensionById(
100 in_progress_prompt_extension_id_, true); 101 in_progress_prompt_extension_id_, true);
101 102
102 in_progress_prompt_extension_id_ = ""; 103 in_progress_prompt_extension_id_ = "";
103 in_progress_prompt_navigation_controller_ = NULL; 104 in_progress_prompt_navigation_controller_ = NULL;
104 extension_install_ui_.reset(); 105 extension_install_ui_.reset();
105 106
106 std::string histogram_name = user_initiated ? 107 std::string histogram_name = user_initiated ?
107 "Extensions.Permissions_ReEnableCancel" : 108 "Extensions.Permissions_ReEnableCancel" :
108 "Extensions.Permissions_ReEnableAbort"; 109 "Extensions.Permissions_ReEnableAbort";
109 ExtensionService::RecordPermissionMessagesHistogram( 110 ExtensionService::RecordPermissionMessagesHistogram(
110 extension, histogram_name.c_str()); 111 extension, histogram_name.c_str());
111 } 112 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_crash_recovery_browsertest.cc ('k') | chrome/browser/extensions/extension_tabs_module.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698