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

Side by Side Diff: chrome/browser/ui/browser.cc

Issue 562533002: Remove deprecated extension notification from Browser (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Rebased and fixed the unittest error Created 6 years, 2 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
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 The Chromium Authors. All rights reserved. 1 // Copyright 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/ui/browser.h" 5 #include "chrome/browser/ui/browser.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shellapi.h> 9 #include <shellapi.h>
10 #endif // defined(OS_WIN) 10 #endif // defined(OS_WIN)
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 #include "content/public/browser/render_view_host.h" 174 #include "content/public/browser/render_view_host.h"
175 #include "content/public/browser/render_widget_host_view.h" 175 #include "content/public/browser/render_widget_host_view.h"
176 #include "content/public/browser/site_instance.h" 176 #include "content/public/browser/site_instance.h"
177 #include "content/public/browser/user_metrics.h" 177 #include "content/public/browser/user_metrics.h"
178 #include "content/public/browser/web_contents.h" 178 #include "content/public/browser/web_contents.h"
179 #include "content/public/common/content_switches.h" 179 #include "content/public/common/content_switches.h"
180 #include "content/public/common/page_zoom.h" 180 #include "content/public/common/page_zoom.h"
181 #include "content/public/common/renderer_preferences.h" 181 #include "content/public/common/renderer_preferences.h"
182 #include "content/public/common/webplugininfo.h" 182 #include "content/public/common/webplugininfo.h"
183 #include "extensions/browser/extension_prefs.h" 183 #include "extensions/browser/extension_prefs.h"
184 #include "extensions/browser/extension_registry.h"
184 #include "extensions/browser/extension_system.h" 185 #include "extensions/browser/extension_system.h"
185 #include "extensions/common/constants.h" 186 #include "extensions/common/constants.h"
186 #include "extensions/common/extension.h" 187 #include "extensions/common/extension.h"
187 #include "extensions/common/manifest_handlers/background_info.h" 188 #include "extensions/common/manifest_handlers/background_info.h"
188 #include "net/base/filename_util.h" 189 #include "net/base/filename_util.h"
189 #include "net/base/registry_controlled_domains/registry_controlled_domain.h" 190 #include "net/base/registry_controlled_domains/registry_controlled_domain.h"
190 #include "net/cookies/cookie_monster.h" 191 #include "net/cookies/cookie_monster.h"
191 #include "net/url_request/url_request_context.h" 192 #include "net/url_request/url_request_context.h"
192 #include "third_party/WebKit/public/web/WebWindowFeatures.h" 193 #include "third_party/WebKit/public/web/WebWindowFeatures.h"
193 #include "ui/base/l10n/l10n_util.h" 194 #include "ui/base/l10n/l10n_util.h"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 private: 323 private:
323 Browser* browser_; 324 Browser* browser_;
324 325
325 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver); 326 DISALLOW_COPY_AND_ASSIGN(InterstitialObserver);
326 }; 327 };
327 328
328 /////////////////////////////////////////////////////////////////////////////// 329 ///////////////////////////////////////////////////////////////////////////////
329 // Browser, Constructors, Creation, Showing: 330 // Browser, Constructors, Creation, Showing:
330 331
331 Browser::Browser(const CreateParams& params) 332 Browser::Browser(const CreateParams& params)
332 : type_(params.type), 333 : extension_registry_observer_(this),
334 type_(params.type),
333 profile_(params.profile), 335 profile_(params.profile),
334 window_(NULL), 336 window_(NULL),
335 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)), 337 tab_strip_model_delegate_(new chrome::BrowserTabStripModelDelegate(this)),
336 tab_strip_model_(new TabStripModel(tab_strip_model_delegate_.get(), 338 tab_strip_model_(
337 params.profile)), 339 new TabStripModel(tab_strip_model_delegate_.get(), params.profile)),
338 app_name_(params.app_name), 340 app_name_(params.app_name),
339 is_trusted_source_(params.trusted_source), 341 is_trusted_source_(params.trusted_source),
340 cancel_download_confirmation_state_(NOT_PROMPTED), 342 cancel_download_confirmation_state_(NOT_PROMPTED),
341 override_bounds_(params.initial_bounds), 343 override_bounds_(params.initial_bounds),
342 initial_show_state_(params.initial_show_state), 344 initial_show_state_(params.initial_show_state),
343 is_session_restore_(params.is_session_restore), 345 is_session_restore_(params.is_session_restore),
344 host_desktop_type_(BrowserWindow::AdjustHostDesktopType( 346 host_desktop_type_(
345 params.host_desktop_type)), 347 BrowserWindow::AdjustHostDesktopType(params.host_desktop_type)),
346 content_setting_bubble_model_delegate_( 348 content_setting_bubble_model_delegate_(
347 new BrowserContentSettingBubbleModelDelegate(this)), 349 new BrowserContentSettingBubbleModelDelegate(this)),
348 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)), 350 toolbar_model_delegate_(new BrowserToolbarModelDelegate(this)),
349 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)), 351 tab_restore_service_delegate_(new BrowserTabRestoreServiceDelegate(this)),
350 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)), 352 synced_window_delegate_(new BrowserSyncedWindowDelegate(this)),
351 bookmark_bar_state_(BookmarkBar::HIDDEN), 353 bookmark_bar_state_(BookmarkBar::HIDDEN),
352 command_controller_(new chrome::BrowserCommandController(this)), 354 command_controller_(new chrome::BrowserCommandController(this)),
353 window_has_shown_(false), 355 window_has_shown_(false),
354 chrome_updater_factory_(this), 356 chrome_updater_factory_(this),
355 translate_driver_observer_( 357 translate_driver_observer_(
(...skipping 11 matching lines...) Expand all
367 fast_unload_controller_.reset(new chrome::FastUnloadController(this)); 369 fast_unload_controller_.reset(new chrome::FastUnloadController(this));
368 else 370 else
369 unload_controller_.reset(new chrome::UnloadController(this)); 371 unload_controller_.reset(new chrome::UnloadController(this));
370 372
371 tab_strip_model_->AddObserver(this); 373 tab_strip_model_->AddObserver(this);
372 374
373 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get())); 375 toolbar_model_.reset(new ToolbarModelImpl(toolbar_model_delegate_.get()));
374 search_model_.reset(new SearchModel()); 376 search_model_.reset(new SearchModel());
375 search_delegate_.reset(new SearchDelegate(search_model_.get())); 377 search_delegate_.reset(new SearchDelegate(search_model_.get()));
376 378
377 registrar_.Add(this, 379 extension_registry_observer_.Add(
378 extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED, 380 extensions::ExtensionRegistry::Get(profile_));
379 content::Source<Profile>(profile_->GetOriginalProfile()));
380 registrar_.Add(this,
381 extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED,
382 content::Source<Profile>(profile_->GetOriginalProfile()));
383 registrar_.Add(this,
384 extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED,
385 content::Source<Profile>(profile_->GetOriginalProfile()));
386 registrar_.Add(this, 381 registrar_.Add(this,
387 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED, 382 extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED,
388 content::NotificationService::AllSources()); 383 content::NotificationService::AllSources());
389 #if defined(ENABLE_THEMES) 384 #if defined(ENABLE_THEMES)
390 registrar_.Add( 385 registrar_.Add(
391 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED, 386 this, chrome::NOTIFICATION_BROWSER_THEME_CHANGED,
392 content::Source<ThemeService>( 387 content::Source<ThemeService>(
393 ThemeServiceFactory::GetForProfile(profile_))); 388 ThemeServiceFactory::GetForProfile(profile_)));
394 #endif 389 #endif
395 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED, 390 registrar_.Add(this, chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED,
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
452 // without a modal dialog host, so that value may be null. 447 // without a modal dialog host, so that value may be null.
453 popup_manager_.reset(new web_modal::PopupManager( 448 popup_manager_.reset(new web_modal::PopupManager(
454 GetWebContentsModalDialogHost())); 449 GetWebContentsModalDialogHost()));
455 } 450 }
456 451
457 Browser::~Browser() { 452 Browser::~Browser() {
458 // Stop observing notifications before continuing with destruction. Profile 453 // Stop observing notifications before continuing with destruction. Profile
459 // destruction will unload extensions and reentrant calls to Browser:: should 454 // destruction will unload extensions and reentrant calls to Browser:: should
460 // be avoided while it is being torn down. 455 // be avoided while it is being torn down.
461 registrar_.RemoveAll(); 456 registrar_.RemoveAll();
457 extension_registry_observer_.RemoveAll();
462 458
463 // The tab strip should not have any tabs at this point. 459 // The tab strip should not have any tabs at this point.
464 DCHECK(tab_strip_model_->empty()); 460 DCHECK(tab_strip_model_->empty());
465 tab_strip_model_->RemoveObserver(this); 461 tab_strip_model_->RemoveObserver(this);
466 462
467 // Destroy the BrowserCommandController before removing the browser, so that 463 // Destroy the BrowserCommandController before removing the browser, so that
468 // it doesn't act on any notifications that are sent as a result of removing 464 // it doesn't act on any notifications that are sent as a result of removing
469 // the browser. 465 // the browser.
470 command_controller_.reset(); 466 command_controller_.reset();
471 BrowserList::RemoveBrowser(this); 467 BrowserList::RemoveBrowser(this);
(...skipping 1477 matching lines...) Expand 10 before | Expand all | Expand 10 after
1949 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false)); 1945 url, Referrer(), CURRENT_TAB, ui::PAGE_TRANSITION_TYPED, false));
1950 } 1946 }
1951 1947
1952 /////////////////////////////////////////////////////////////////////////////// 1948 ///////////////////////////////////////////////////////////////////////////////
1953 // Browser, content::NotificationObserver implementation: 1949 // Browser, content::NotificationObserver implementation:
1954 1950
1955 void Browser::Observe(int type, 1951 void Browser::Observe(int type,
1956 const content::NotificationSource& source, 1952 const content::NotificationSource& source,
1957 const content::NotificationDetails& details) { 1953 const content::NotificationDetails& details) {
1958 switch (type) { 1954 switch (type) {
1959 case extensions::NOTIFICATION_EXTENSION_UNLOADED_DEPRECATED: {
1960 chrome::UpdateCommandEnabled(
1961 this,
1962 IDC_BOOKMARK_PAGE,
1963 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
1964 chrome::UpdateCommandEnabled(
1965 this,
1966 IDC_BOOKMARK_ALL_TABS,
1967 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
1968
1969 if (window()->GetLocationBar())
1970 window()->GetLocationBar()->UpdatePageActions();
1971
1972 const extensions::UnloadedExtensionInfo* extension_info =
1973 content::Details<extensions::UnloadedExtensionInfo>(details).ptr();
1974
1975 // Close any tabs from the unloaded extension, unless it's terminated,
1976 // in which case let the sad tabs remain.
1977 if (extension_info->reason !=
1978 extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
1979 const Extension* extension = extension_info->extension;
1980 // Iterate backwards as we may remove items while iterating.
1981 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
1982 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
1983 // Two cases are handled here:
1984 // - The scheme check is for when an extension page is loaded in a
1985 // tab, e.g. chrome-extension://id/page.html.
1986 // - The extension_app check is for apps, which can have non-extension
1987 // schemes, e.g. https://mail.google.com if you have the Gmail app
1988 // installed.
1989 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
1990 web_contents->GetURL().host() == extension->id()) ||
1991 (extensions::TabHelper::FromWebContents(
1992 web_contents)->extension_app() == extension)) {
1993 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
1994 }
1995 }
1996 }
1997 break;
1998 }
1999
2000 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: { 1955 case extensions::NOTIFICATION_EXTENSION_PROCESS_TERMINATED: {
2001 Profile* profile = content::Source<Profile>(source).ptr(); 1956 Profile* profile = content::Source<Profile>(source).ptr();
2002 if (profile_->IsSameProfile(profile) && window()->GetLocationBar()) 1957 if (profile_->IsSameProfile(profile) && window()->GetLocationBar())
2003 window()->GetLocationBar()->InvalidatePageActions(); 1958 window()->GetLocationBar()->InvalidatePageActions();
2004 break; 1959 break;
2005 } 1960 }
2006 1961
2007 case extensions::NOTIFICATION_EXTENSION_LOADED_DEPRECATED:
2008 chrome::UpdateCommandEnabled(
2009 this,
2010 IDC_BOOKMARK_PAGE,
2011 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
2012 chrome::UpdateCommandEnabled(
2013 this,
2014 IDC_BOOKMARK_ALL_TABS,
2015 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
2016 // fallthrough
2017 case extensions::NOTIFICATION_EXTENSION_UNINSTALLED_DEPRECATED:
2018 // During window creation on Windows we may end up calling into
2019 // SHAppBarMessage, which internally spawns a nested message loop. This
2020 // makes it possible for us to end up here before window creation has
2021 // completed, at which point window_ is NULL. See 94752 for details.
2022 if (window() && window()->GetLocationBar())
2023 window()->GetLocationBar()->UpdatePageActions();
2024 break;
2025
2026 #if defined(ENABLE_THEMES) 1962 #if defined(ENABLE_THEMES)
2027 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED: 1963 case chrome::NOTIFICATION_BROWSER_THEME_CHANGED:
2028 window()->UserChangedTheme(); 1964 window()->UserChangedTheme();
2029 break; 1965 break;
2030 #endif 1966 #endif
2031 1967
2032 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: { 1968 case chrome::NOTIFICATION_WEB_CONTENT_SETTINGS_CHANGED: {
2033 WebContents* web_contents = content::Source<WebContents>(source).ptr(); 1969 WebContents* web_contents = content::Source<WebContents>(source).ptr();
2034 if (web_contents == tab_strip_model_->GetActiveWebContents()) { 1970 if (web_contents == tab_strip_model_->GetActiveWebContents()) {
2035 LocationBar* location_bar = window()->GetLocationBar(); 1971 LocationBar* location_bar = window()->GetLocationBar();
2036 if (location_bar) 1972 if (location_bar)
2037 location_bar->UpdateContentSettingsIcons(); 1973 location_bar->UpdateContentSettingsIcons();
2038 } 1974 }
2039 break; 1975 break;
2040 } 1976 }
2041 1977
2042 default: 1978 default:
2043 NOTREACHED() << "Got a notification we didn't register for."; 1979 NOTREACHED() << "Got a notification we didn't register for.";
2044 } 1980 }
2045 } 1981 }
2046 1982
2047 /////////////////////////////////////////////////////////////////////////////// 1983 ///////////////////////////////////////////////////////////////////////////////
1984 // Browser, extensions::ExtensionRegistryObserver implementation:
1985
1986 void Browser::OnExtensionUninstalled(content::BrowserContext* browser_context,
1987 const extensions::Extension* extension,
1988 extensions::UninstallReason reason) {
1989 // During window creation on Windows we may end up calling into
1990 // SHAppBarMessage, which internally spawns a nested message loop.This
1991 // makes it possible for us to end up here before window creation has
1992 // completed, at which point window_ is NULL. See 94752 for details.
1993
1994 if (window() && window()->GetLocationBar())
1995 window()->GetLocationBar()->UpdatePageActions();
1996 }
1997
1998 void Browser::OnExtensionLoaded(content::BrowserContext* browser_context,
1999 const extensions::Extension* extension) {
2000 chrome::UpdateCommandEnabled(
2001 this,
2002 IDC_BOOKMARK_PAGE,
2003 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
2004 chrome::UpdateCommandEnabled(
2005 this,
2006 IDC_BOOKMARK_ALL_TABS,
2007 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
2008 }
2009
2010 void Browser::OnExtensionUnloaded(
2011 content::BrowserContext* browser_context,
2012 const extensions::Extension* extension,
2013 extensions::UnloadedExtensionInfo::Reason reason) {
2014 chrome::UpdateCommandEnabled(
2015 this,
2016 IDC_BOOKMARK_PAGE,
2017 !chrome::ShouldRemoveBookmarkThisPageUI(profile_));
2018 chrome::UpdateCommandEnabled(
2019 this,
2020 IDC_BOOKMARK_ALL_TABS,
2021 !chrome::ShouldRemoveBookmarkOpenPagesUI(profile_));
2022 if (window()->GetLocationBar())
2023 window()->GetLocationBar()->UpdatePageActions();
2024
2025 // Close any tabs from the unloaded extension, unless it's terminated,
2026 // in which case let the sad tabs remain.
2027 if (reason != extensions::UnloadedExtensionInfo::REASON_TERMINATE) {
2028 // Iterate backwards as we may remove items while iterating.
2029 for (int i = tab_strip_model_->count() - 1; i >= 0; --i) {
2030 WebContents* web_contents = tab_strip_model_->GetWebContentsAt(i);
2031 // Two cases are handled here:
2032
2033 // - The scheme check is for when an extension page is loaded in a
2034 // tab, e.g. chrome-extension://id/page.html.
2035 // - The extension_app check is for apps, which can have non-extension
2036 // schemes, e.g. https://mail.google.com if you have the Gmail app
2037 // installed.
2038 if ((web_contents->GetURL().SchemeIs(extensions::kExtensionScheme) &&
2039 web_contents->GetURL().host() == extension->id()) ||
2040 (extensions::TabHelper::FromWebContents(web_contents)
2041 ->extension_app() == extension)) {
2042 tab_strip_model_->CloseWebContentsAt(i, TabStripModel::CLOSE_NONE);
2043 }
2044 }
2045 }
2046 }
2047
2048 ///////////////////////////////////////////////////////////////////////////////
2048 // Browser, Command and state updating (private): 2049 // Browser, Command and state updating (private):
2049 2050
2050 void Browser::OnDevToolsDisabledChanged() { 2051 void Browser::OnDevToolsDisabledChanged() {
2051 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) 2052 if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled))
2052 content::DevToolsAgentHost::DetachAllClients(); 2053 content::DevToolsAgentHost::DetachAllClients();
2053 } 2054 }
2054 2055
2055 /////////////////////////////////////////////////////////////////////////////// 2056 ///////////////////////////////////////////////////////////////////////////////
2056 // Browser, UI update coalescing and handling (private): 2057 // Browser, UI update coalescing and handling (private):
2057 2058
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
2492 if (contents && !allow_js_access) { 2493 if (contents && !allow_js_access) {
2493 contents->web_contents()->GetController().LoadURL( 2494 contents->web_contents()->GetController().LoadURL(
2494 target_url, 2495 target_url,
2495 content::Referrer(), 2496 content::Referrer(),
2496 ui::PAGE_TRANSITION_LINK, 2497 ui::PAGE_TRANSITION_LINK,
2497 std::string()); // No extra headers. 2498 std::string()); // No extra headers.
2498 } 2499 }
2499 2500
2500 return contents != NULL; 2501 return contents != NULL;
2501 } 2502 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/browser.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698