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

Side by Side Diff: chrome/browser/tab_contents/web_contents.cc

Issue 19746: Remove old web app code it's no longer needed. Simplifies startup a little. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/tab_contents/web_contents.h" 5 #include "chrome/browser/tab_contents/web_contents.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/compiler_specific.h" 8 #include "base/compiler_specific.h"
9 #include "base/file_version_info.h" 9 #include "base/file_version_info.h"
10 #include "base/process_util.h" 10 #include "base/process_util.h"
11 #include "chrome/app/locales/locale_settings.h" 11 #include "chrome/app/locales/locale_settings.h"
12 #include "chrome/browser/autofill_manager.h" 12 #include "chrome/browser/autofill_manager.h"
13 #include "chrome/browser/bookmarks/bookmark_model.h" 13 #include "chrome/browser/bookmarks/bookmark_model.h"
14 #include "chrome/browser/browser.h" 14 #include "chrome/browser/browser.h"
15 #include "chrome/browser/cache_manager_host.h" 15 #include "chrome/browser/cache_manager_host.h"
16 #include "chrome/browser/character_encoding.h" 16 #include "chrome/browser/character_encoding.h"
17 #include "chrome/browser/dom_operation_notification_details.h" 17 #include "chrome/browser/dom_operation_notification_details.h"
18 #include "chrome/browser/download/download_manager.h" 18 #include "chrome/browser/download/download_manager.h"
19 #include "chrome/browser/download/download_request_manager.h" 19 #include "chrome/browser/download/download_request_manager.h"
20 #include "chrome/browser/gears_integration.h"
20 #include "chrome/browser/google_util.h" 21 #include "chrome/browser/google_util.h"
21 #include "chrome/browser/js_before_unload_handler.h" 22 #include "chrome/browser/js_before_unload_handler.h"
22 #include "chrome/browser/jsmessage_box_handler.h" 23 #include "chrome/browser/jsmessage_box_handler.h"
23 #include "chrome/browser/load_from_memory_cache_details.h" 24 #include "chrome/browser/load_from_memory_cache_details.h"
24 #include "chrome/browser/load_notification_details.h" 25 #include "chrome/browser/load_notification_details.h"
25 #include "chrome/browser/modal_html_dialog_delegate.h" 26 #include "chrome/browser/modal_html_dialog_delegate.h"
26 #include "chrome/browser/password_manager/password_manager.h" 27 #include "chrome/browser/password_manager/password_manager.h"
27 #include "chrome/browser/plugin_installer.h" 28 #include "chrome/browser/plugin_installer.h"
28 #include "chrome/browser/plugin_service.h" 29 #include "chrome/browser/plugin_service.h"
29 #include "chrome/browser/printing/print_job.h" 30 #include "chrome/browser/printing/print_job.h"
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 this, NotificationType::URLS_STARRED, NotificationService::AllSources()); 209 this, NotificationType::URLS_STARRED, NotificationService::AllSources());
209 NotificationService::current()->AddObserver( 210 NotificationService::current()->AddObserver(
210 this, NotificationType::BOOKMARK_MODEL_LOADED, 211 this, NotificationType::BOOKMARK_MODEL_LOADED,
211 NotificationService::AllSources()); 212 NotificationService::AllSources());
212 NotificationService::current()->AddObserver( 213 NotificationService::current()->AddObserver(
213 this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, 214 this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
214 NotificationService::AllSources()); 215 NotificationService::AllSources());
215 } 216 }
216 217
217 WebContents::~WebContents() { 218 WebContents::~WebContents() {
218 if (web_app_.get())
219 web_app_->RemoveObserver(this);
220 if (pending_install_.callback_functor) 219 if (pending_install_.callback_functor)
221 pending_install_.callback_functor->Cancel(); 220 pending_install_.callback_functor->Cancel();
222 NotificationService::current()->RemoveObserver( 221 NotificationService::current()->RemoveObserver(
223 this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, 222 this, NotificationType::RENDER_WIDGET_HOST_DESTROYED,
224 NotificationService::AllSources()); 223 NotificationService::AllSources());
225 } 224 }
226 225
227 // static 226 // static
228 void WebContents::RegisterUserPrefs(PrefService* prefs) { 227 void WebContents::RegisterUserPrefs(PrefService* prefs) {
229 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true); 228 prefs->RegisterBooleanPref(prefs::kAlternateErrorPagesEnabled, true);
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
322 NotifyDisconnected(); 321 NotifyDisconnected();
323 HungRendererWarning::HideForWebContents(this); 322 HungRendererWarning::HideForWebContents(this);
324 render_manager_.Shutdown(); 323 render_manager_.Shutdown();
325 TabContents::Destroy(); 324 TabContents::Destroy();
326 } 325 }
327 326
328 SiteInstance* WebContents::GetSiteInstance() const { 327 SiteInstance* WebContents::GetSiteInstance() const {
329 return render_manager_.current_host()->site_instance(); 328 return render_manager_.current_host()->site_instance();
330 } 329 }
331 330
332 SkBitmap WebContents::GetFavIcon() {
333 if (web_app_.get() && IsWebApplicationActive()) {
334 SkBitmap app_icon = web_app_->GetFavIcon();
335 if (!app_icon.isNull())
336 return app_icon;
337 }
338 return TabContents::GetFavIcon();
339 }
340
341 std::wstring WebContents::GetStatusText() const { 331 std::wstring WebContents::GetStatusText() const {
342 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE) 332 if (!is_loading() || load_state_ == net::LOAD_STATE_IDLE)
343 return std::wstring(); 333 return std::wstring();
344 334
345 switch (load_state_) { 335 switch (load_state_) {
346 case net::LOAD_STATE_WAITING_FOR_CACHE: 336 case net::LOAD_STATE_WAITING_FOR_CACHE:
347 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE); 337 return l10n_util::GetString(IDS_LOAD_STATE_WAITING_FOR_CACHE);
348 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL: 338 case net::LOAD_STATE_RESOLVING_PROXY_FOR_URL:
349 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL); 339 return l10n_util::GetString(IDS_LOAD_STATE_RESOLVING_PROXY_FOR_URL);
350 case net::LOAD_STATE_RESOLVING_HOST: 340 case net::LOAD_STATE_RESOLVING_HOST:
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 HWND WebContents::GetContainerHWND() const { 482 HWND WebContents::GetContainerHWND() const {
493 return view_->GetNativeView(); 483 return view_->GetNativeView();
494 } 484 }
495 HWND WebContents::GetContentHWND() { 485 HWND WebContents::GetContentHWND() {
496 return view_->GetContentNativeView(); 486 return view_->GetContentNativeView();
497 } 487 }
498 void WebContents::GetContainerBounds(gfx::Rect *out) const { 488 void WebContents::GetContainerBounds(gfx::Rect *out) const {
499 view_->GetContainerBounds(out); 489 view_->GetContainerBounds(out);
500 } 490 }
501 491
502 void WebContents::SetWebApp(WebApp* web_app) {
503 if (web_app_.get()) {
504 web_app_->RemoveObserver(this);
505 web_app_->SetWebContents(NULL);
506 }
507
508 web_app_ = web_app;
509 if (web_app) {
510 web_app->AddObserver(this);
511 web_app_->SetWebContents(this);
512 }
513 }
514
515 bool WebContents::IsWebApplication() const {
516 return (web_app_.get() != NULL);
517 }
518
519 void WebContents::CreateShortcut() { 492 void WebContents::CreateShortcut() {
520 NavigationEntry* entry = controller()->GetLastCommittedEntry(); 493 NavigationEntry* entry = controller()->GetLastCommittedEntry();
521 if (!entry) 494 if (!entry)
522 return; 495 return;
523 496
524 // We only allow one pending install request. By resetting the page id we 497 // We only allow one pending install request. By resetting the page id we
525 // effectively cancel the pending install request. 498 // effectively cancel the pending install request.
526 pending_install_.page_id = entry->page_id(); 499 pending_install_.page_id = entry->page_id();
527 pending_install_.icon = GetFavIcon(); 500 pending_install_.icon = GetFavIcon();
528 pending_install_.title = GetTitle(); 501 pending_install_.title = GetTitle();
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
934 bool errored, 907 bool errored,
935 const SkBitmap& image) { 908 const SkBitmap& image) {
936 // A notification for downloading would be more flexible, but for now I'm 909 // A notification for downloading would be more flexible, but for now I'm
937 // forwarding to the two places that could possibly have initiated the 910 // forwarding to the two places that could possibly have initiated the
938 // request. If we end up with another place invoking DownloadImage, probably 911 // request. If we end up with another place invoking DownloadImage, probably
939 // best to refactor out into notification service, or something similar. 912 // best to refactor out into notification service, or something similar.
940 if (errored) 913 if (errored)
941 fav_icon_helper_.FavIconDownloadFailed(id); 914 fav_icon_helper_.FavIconDownloadFailed(id);
942 else 915 else
943 fav_icon_helper_.SetFavIcon(id, image_url, image); 916 fav_icon_helper_.SetFavIcon(id, image_url, image);
944 if (web_app_.get() && !errored)
945 web_app_->SetImage(image_url, image);
946 } 917 }
947 918
948 void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer, 919 void WebContents::RequestOpenURL(const GURL& url, const GURL& referrer,
949 WindowOpenDisposition disposition) { 920 WindowOpenDisposition disposition) {
950 OpenURL(url, referrer, disposition, PageTransition::LINK); 921 OpenURL(url, referrer, disposition, PageTransition::LINK);
951 } 922 }
952 923
953 void WebContents::DomOperationResponse(const std::string& json_string, 924 void WebContents::DomOperationResponse(const std::string& json_string,
954 int automation_id) { 925 int automation_id) {
955 DomOperationNotificationDetails details(json_string, automation_id); 926 DomOperationNotificationDetails details(json_string, automation_id);
(...skipping 581 matching lines...) Expand 10 before | Expand all | Expand 10 after
1537 1508
1538 void WebContents::UpdateAlternateErrorPageURL() { 1509 void WebContents::UpdateAlternateErrorPageURL() {
1539 GURL url = GetAlternateErrorPageURL(); 1510 GURL url = GetAlternateErrorPageURL();
1540 render_view_host()->SetAlternateErrorPageURL(url); 1511 render_view_host()->SetAlternateErrorPageURL(url);
1541 } 1512 }
1542 1513
1543 void WebContents::UpdateWebPreferences() { 1514 void WebContents::UpdateWebPreferences() {
1544 render_view_host()->UpdateWebPreferences(GetWebkitPrefs()); 1515 render_view_host()->UpdateWebPreferences(GetWebkitPrefs());
1545 } 1516 }
1546 1517
1547 bool WebContents::IsWebApplicationActive() const {
1548 if (!web_app_.get())
1549 return false;
1550
1551 // If we are inside an application, the application is always active. For
1552 // example, this allows us to display the GMail icon even when we are bounced
1553 // the login page.
1554 if (delegate() && delegate()->IsApplication())
1555 return true;
1556
1557 return (GetURL() == web_app_->url());
1558 }
1559
1560 void WebContents::WebAppImagesChanged(WebApp* web_app) {
1561 DCHECK(web_app == web_app_.get());
1562 if (delegate() && IsWebApplicationActive())
1563 delegate()->NavigationStateChanged(this, TabContents::INVALIDATE_FAVICON);
1564 }
1565
1566 void WebContents::OnGearsCreateShortcutDone( 1518 void WebContents::OnGearsCreateShortcutDone(
1567 const GearsShortcutData& shortcut_data, bool success) { 1519 const GearsShortcutData& shortcut_data, bool success) {
1568 NavigationEntry* current_entry = controller()->GetLastCommittedEntry(); 1520 NavigationEntry* current_entry = controller()->GetLastCommittedEntry();
1569 bool same_page = 1521 bool same_page =
1570 current_entry && pending_install_.page_id == current_entry->page_id(); 1522 current_entry && pending_install_.page_id == current_entry->page_id();
1571 1523
1572 if (success && same_page) { 1524 if (success && same_page) {
1573 // Only switch to app mode if the user chose to create a shortcut and 1525 // Only switch to app mode if the user chose to create a shortcut and
1574 // we're still on the same page that it corresponded to. 1526 // we're still on the same page that it corresponded to.
1575 SetWebApp(new WebApp(profile(), shortcut_data));
1576 if (delegate()) 1527 if (delegate())
1577 delegate()->ConvertContentsToApplication(this); 1528 delegate()->ConvertContentsToApplication(this);
1578 } 1529 }
1579 1530
1580 // Reset the page id to indicate no requests are pending. 1531 // Reset the page id to indicate no requests are pending.
1581 pending_install_.page_id = 0; 1532 pending_install_.page_id = 0;
1582 pending_install_.callback_functor = NULL; 1533 pending_install_.callback_functor = NULL;
1583 } 1534 }
1584 1535
1585 void WebContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, 1536 void WebContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance,
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
1769 // The favicon url isn't valid. This means there really isn't a favicon, 1720 // The favicon url isn't valid. This means there really isn't a favicon,
1770 // or the favicon url wasn't obtained before the load started. This assumes 1721 // or the favicon url wasn't obtained before the load started. This assumes
1771 // the later. 1722 // the later.
1772 // TODO(sky): Need a way to set the favicon that doesn't involve generating 1723 // TODO(sky): Need a way to set the favicon that doesn't involve generating
1773 // its url. 1724 // its url.
1774 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer)); 1725 new_url->SetFavIconURL(TemplateURL::GenerateFaviconURL(params.referrer));
1775 } 1726 }
1776 new_url->set_safe_for_autoreplace(true); 1727 new_url->set_safe_for_autoreplace(true);
1777 url_model->Add(new_url); 1728 url_model->Add(new_url);
1778 } 1729 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698