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

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

Issue 10824204: Move small c/b/extensions classes into extensions namespace no.2 (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for cq + nitfix Created 8 years, 4 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/extension_navigation_observer.h" 5 #include "chrome/browser/extensions/navigation_observer.h"
6 6
7 #include "chrome/browser/extensions/extension_install_ui.h" 7 #include "chrome/browser/extensions/extension_install_ui.h"
8 #include "chrome/browser/extensions/extension_service.h" 8 #include "chrome/browser/extensions/extension_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/navigation_entry.h" 11 #include "content/public/browser/navigation_entry.h"
12 #include "content/public/browser/notification_service.h" 12 #include "content/public/browser/notification_service.h"
13 #include "content/public/browser/notification_types.h" 13 #include "content/public/browser/notification_types.h"
14 14
15 using content::NavigationController; 15 using content::NavigationController;
16 using content::NavigationEntry; 16 using content::NavigationEntry;
17 17
18 ExtensionNavigationObserver::ExtensionNavigationObserver(Profile* profile) 18 namespace extensions {
19 : profile_(profile) { 19
20 NavigationObserver::NavigationObserver(Profile* profile) : profile_(profile) {
20 RegisterForNotifications(); 21 RegisterForNotifications();
21 } 22 }
22 23
23 ExtensionNavigationObserver::~ExtensionNavigationObserver() {} 24 NavigationObserver::~NavigationObserver() {}
24 25
25 void ExtensionNavigationObserver::Observe( 26 void NavigationObserver::Observe(int type,
26 int type, 27 const content::NotificationSource& source,
27 const content::NotificationSource& source, 28 const content::NotificationDetails& details) {
28 const content::NotificationDetails& details) {
29 if (type != content::NOTIFICATION_NAV_ENTRY_COMMITTED) { 29 if (type != content::NOTIFICATION_NAV_ENTRY_COMMITTED) {
30 NOTREACHED(); 30 NOTREACHED();
31 return; 31 return;
32 } 32 }
33 33
34 NavigationController* controller = 34 NavigationController* controller =
35 content::Source<NavigationController>(source).ptr(); 35 content::Source<NavigationController>(source).ptr();
36 if (!profile_->IsSameProfile( 36 if (!profile_->IsSameProfile(
37 Profile::FromBrowserContext(controller->GetBrowserContext()))) 37 Profile::FromBrowserContext(controller->GetBrowserContext())))
38 return; 38 return;
39 39
40 PromptToEnableExtensionIfNecessary(controller); 40 PromptToEnableExtensionIfNecessary(controller);
41 } 41 }
42 42
43 void ExtensionNavigationObserver::RegisterForNotifications() { 43 void NavigationObserver::RegisterForNotifications() {
44 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 44 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
45 content::NotificationService::AllSources()); 45 content::NotificationService::AllSources());
46 } 46 }
47 47
48 void ExtensionNavigationObserver::PromptToEnableExtensionIfNecessary( 48 void NavigationObserver::PromptToEnableExtensionIfNecessary(
49 NavigationController* nav_controller) { 49 NavigationController* nav_controller) {
50 // Bail out if we're already running a prompt. 50 // Bail out if we're already running a prompt.
51 if (!in_progress_prompt_extension_id_.empty()) 51 if (!in_progress_prompt_extension_id_.empty())
52 return; 52 return;
53 53
54 NavigationEntry* nav_entry = nav_controller->GetActiveEntry(); 54 NavigationEntry* nav_entry = nav_controller->GetActiveEntry();
55 if (!nav_entry) 55 if (!nav_entry)
56 return; 56 return;
57 57
58 ExtensionService* extension_service = profile_->GetExtensionService(); 58 ExtensionService* extension_service = profile_->GetExtensionService();
59 const extensions::Extension* extension = 59 const Extension* extension = extension_service->disabled_extensions()->
60 extension_service->disabled_extensions()->
61 GetExtensionOrAppByURL(ExtensionURLInfo(nav_entry->GetURL())); 60 GetExtensionOrAppByURL(ExtensionURLInfo(nav_entry->GetURL()));
62 if (!extension) 61 if (!extension)
63 return; 62 return;
64 63
65 // Try not to repeatedly prompt the user about the same extension. 64 // Try not to repeatedly prompt the user about the same extension.
66 if (prompted_extensions_.find(extension->id()) != prompted_extensions_.end()) 65 if (prompted_extensions_.find(extension->id()) != prompted_extensions_.end())
67 return; 66 return;
68 prompted_extensions_.insert(extension->id()); 67 prompted_extensions_.insert(extension->id());
69 68
70 extensions::ExtensionPrefs* extension_prefs = 69 ExtensionPrefs* extension_prefs = extension_service->extension_prefs();
71 extension_service->extension_prefs();
72 if (extension_prefs->DidExtensionEscalatePermissions(extension->id())) { 70 if (extension_prefs->DidExtensionEscalatePermissions(extension->id())) {
73 // Keep track of the extension id and nav controller we're prompting for. 71 // Keep track of the extension id and nav controller we're prompting for.
74 // These must be reset in InstallUIProceed and InstallUIAbort. 72 // These must be reset in InstallUIProceed and InstallUIAbort.
75 in_progress_prompt_extension_id_ = extension->id(); 73 in_progress_prompt_extension_id_ = extension->id();
76 in_progress_prompt_navigation_controller_ = nav_controller; 74 in_progress_prompt_navigation_controller_ = nav_controller;
77 75
78 extension_install_prompt_.reset( 76 extension_install_prompt_.reset(
79 ExtensionInstallUI::CreateInstallPromptWithWebContents( 77 ExtensionInstallUI::CreateInstallPromptWithWebContents(
80 nav_controller->GetWebContents())); 78 nav_controller->GetWebContents()));
81 extension_install_prompt_->ConfirmReEnable(this, extension); 79 extension_install_prompt_->ConfirmReEnable(this, extension);
82 } 80 }
83 } 81 }
84 82
85 void ExtensionNavigationObserver::InstallUIProceed() { 83 void NavigationObserver::InstallUIProceed() {
86 ExtensionService* extension_service = profile_->GetExtensionService(); 84 ExtensionService* extension_service = profile_->GetExtensionService();
87 const extensions::Extension* extension = extension_service->GetExtensionById( 85 const Extension* extension = extension_service->GetExtensionById(
88 in_progress_prompt_extension_id_, true); 86 in_progress_prompt_extension_id_, true);
89 NavigationController* nav_controller = 87 NavigationController* nav_controller =
90 in_progress_prompt_navigation_controller_; 88 in_progress_prompt_navigation_controller_;
91 CHECK(extension); 89 CHECK(extension);
92 CHECK(nav_controller); 90 CHECK(nav_controller);
93 91
94 in_progress_prompt_extension_id_ = ""; 92 in_progress_prompt_extension_id_ = "";
95 in_progress_prompt_navigation_controller_ = NULL; 93 in_progress_prompt_navigation_controller_ = NULL;
96 extension_install_prompt_.reset(); 94 extension_install_prompt_.reset();
97 95
98 // Grant permissions, re-enable the extension, and then reload the tab. 96 // Grant permissions, re-enable the extension, and then reload the tab.
99 extension_service->GrantPermissionsAndEnableExtension( 97 extension_service->GrantPermissionsAndEnableExtension(
100 extension, extension_install_prompt_->record_oauth2_grant()); 98 extension, extension_install_prompt_->record_oauth2_grant());
101 nav_controller->Reload(true); 99 nav_controller->Reload(true);
102 } 100 }
103 101
104 void ExtensionNavigationObserver::InstallUIAbort(bool user_initiated) { 102 void NavigationObserver::InstallUIAbort(bool user_initiated) {
105 ExtensionService* extension_service = profile_->GetExtensionService(); 103 ExtensionService* extension_service = profile_->GetExtensionService();
106 const extensions::Extension* extension = extension_service->GetExtensionById( 104 const Extension* extension = extension_service->GetExtensionById(
107 in_progress_prompt_extension_id_, true); 105 in_progress_prompt_extension_id_, true);
108 106
109 in_progress_prompt_extension_id_ = ""; 107 in_progress_prompt_extension_id_ = "";
110 in_progress_prompt_navigation_controller_ = NULL; 108 in_progress_prompt_navigation_controller_ = NULL;
111 extension_install_prompt_.reset(); 109 extension_install_prompt_.reset();
112 110
113 std::string histogram_name = user_initiated ? 111 std::string histogram_name = user_initiated ?
114 "Extensions.Permissions_ReEnableCancel" : 112 "Extensions.Permissions_ReEnableCancel" :
115 "Extensions.Permissions_ReEnableAbort"; 113 "Extensions.Permissions_ReEnableAbort";
116 ExtensionService::RecordPermissionMessagesHistogram( 114 ExtensionService::RecordPermissionMessagesHistogram(
117 extension, histogram_name.c_str()); 115 extension, histogram_name.c_str());
118 } 116 }
117
118 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/navigation_observer.h ('k') | chrome/browser/extensions/pack_extension_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698