diff options
Diffstat (limited to 'chrome/browser/tab_contents')
24 files changed, 379 insertions, 97 deletions
diff --git a/chrome/browser/tab_contents/background_contents.h b/chrome/browser/tab_contents/background_contents.h index 0e48416..63a30d9 100644 --- a/chrome/browser/tab_contents/background_contents.h +++ b/chrome/browser/tab_contents/background_contents.h @@ -7,6 +7,7 @@ #pragma once #include <string> +#include <vector> #include "chrome/browser/js_modal_dialog.h" #include "chrome/browser/renderer_host/render_view_host_delegate.h" @@ -90,6 +91,12 @@ class BackgroundContents : public RenderViewHostDelegate, const gfx::Rect& initial_pos); virtual void ShowCreatedFullscreenWidget(int route_id); virtual void ShowContextMenu(const ContextMenuParams& params) {} + virtual void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) {} virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_operations, const SkBitmap& image, diff --git a/chrome/browser/tab_contents/interstitial_page.cc b/chrome/browser/tab_contents/interstitial_page.cc index 8663eef..ae1e078 100644 --- a/chrome/browser/tab_contents/interstitial_page.cc +++ b/chrome/browser/tab_contents/interstitial_page.cc @@ -104,6 +104,12 @@ class InterstitialPage::InterstitialPageRVHViewDelegate const gfx::Rect& initial_pos); virtual void ShowCreatedFullscreenWidget(int route_id); virtual void ShowContextMenu(const ContextMenuParams& params); + virtual void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned); virtual void StartDragging(const WebDropData& drop_data, WebDragOperationsMask operations_allowed, const SkBitmap& image, @@ -615,6 +621,15 @@ void InterstitialPage::InterstitialPageRVHViewDelegate::ShowContextMenu( const ContextMenuParams& params) { } +void InterstitialPage::InterstitialPageRVHViewDelegate::ShowPopupMenu( + const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) { +} + void InterstitialPage::InterstitialPageRVHViewDelegate::StartDragging( const WebDropData& drop_data, WebDragOperationsMask allowed_operations, @@ -699,8 +714,9 @@ int InterstitialPage::GetBrowserWindowID() const { } void InterstitialPage::UpdateInspectorSetting(const std::string& key, - const std::string& value) { - RenderViewHostDelegateHelper::UpdateInspectorSetting(tab_->profile(), key, value); + const std::string& value) { + RenderViewHostDelegateHelper::UpdateInspectorSetting( + tab_->profile(), key, value); } void InterstitialPage::ClearInspectorSettings() { diff --git a/chrome/browser/tab_contents/popup_menu_helper_mac.h b/chrome/browser/tab_contents/popup_menu_helper_mac.h new file mode 100644 index 0000000..08a4c19 --- /dev/null +++ b/chrome/browser/tab_contents/popup_menu_helper_mac.h @@ -0,0 +1,46 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_TAB_CONTENTS_POPUP_MENU_HELPER_MAC_H_ +#define CHROME_BROWSER_TAB_CONTENTS_POPUP_MENU_HELPER_MAC_H_ + +#include <vector> + +#include "chrome/common/notification_observer.h" +#include "chrome/common/notification_registrar.h" +#include "gfx/rect.h" + +class RenderViewHost; +struct WebMenuItem; + +class PopupMenuHelper : public NotificationObserver { + public: + // Creates a PopupMenuHelper that will notify |render_view_host| when a user + // selects or cancels the popup. + explicit PopupMenuHelper(RenderViewHost* render_view_host); + + // Shows the popup menu and notifies the RenderViewHost of the selection/ + // cancel. + // This call is blocking. + void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned); + + private: + // NotificationObserver implementation: + virtual void Observe(NotificationType type, + const NotificationSource& source, + const NotificationDetails& details); + + NotificationRegistrar notification_registrar_; + + RenderViewHost* render_view_host_; + + DISALLOW_COPY_AND_ASSIGN(PopupMenuHelper); +}; + +#endif // CHROME_BROWSER_TAB_CONTENTS_POPUP_MENU_HELPER_MAC_H_ diff --git a/chrome/browser/tab_contents/popup_menu_helper_mac.mm b/chrome/browser/tab_contents/popup_menu_helper_mac.mm new file mode 100644 index 0000000..0e910b7 --- /dev/null +++ b/chrome/browser/tab_contents/popup_menu_helper_mac.mm @@ -0,0 +1,87 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#import <Carbon/Carbon.h> + +#include "chrome/browser/tab_contents/popup_menu_helper_mac.h" + +#import "base/chrome_application_mac.h" +#include "base/message_loop.h" +#include "base/scoped_nsobject.h" +#import "chrome/browser/cocoa/base_view.h" +#include "chrome/browser/renderer_host/render_view_host.h" +#include "chrome/browser/renderer_host/render_widget_host_view_mac.h" +#include "chrome/common/notification_source.h" +#include "webkit/glue/webmenurunner_mac.h" + +PopupMenuHelper::PopupMenuHelper(RenderViewHost* render_view_host) + : render_view_host_(render_view_host) { + notification_registrar_.Add( + this, NotificationType::RENDER_WIDGET_HOST_DESTROYED, + Source<RenderWidgetHost>(render_view_host)); +} + +void PopupMenuHelper::ShowPopupMenu( + const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) { + // Retain the Cocoa view for the duration of the pop-up so that it can't be + // dealloced if my Destroy() method is called while the pop-up's up (which + // would in turn delete me, causing a crash once the -runMenuInView + // call returns. That's what was happening in <http://crbug.com/33250>). + RenderWidgetHostViewMac* rwhvm = + static_cast<RenderWidgetHostViewMac*>(render_view_host_->view()); + scoped_nsobject<RenderWidgetHostViewCocoa> cocoa_view + ([rwhvm->native_view() retain]); + + // Display the menu. + scoped_nsobject<WebMenuRunner> menu_runner; + menu_runner.reset([[WebMenuRunner alloc] initWithItems:items + fontSize:item_font_size + rightAligned:right_aligned]); + + { + // Make sure events can be pumped while the menu is up. + MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); + + // One of the events that could be pumped is |window.close()|. + // User-initiated event-tracking loops protect against this by + // setting flags in -[CrApplication sendEvent:], but since + // web-content menus are initiated by IPC message the setup has to + // be done manually. + chrome_application_mac::ScopedSendingEvent sendingEventScoper; + + // Now run a SYNCHRONOUS NESTED EVENT LOOP until the pop-up is finished. + [menu_runner runMenuInView:cocoa_view + withBounds:[cocoa_view flipRectToNSRect:bounds] + initialIndex:selected_item]; + } + + if (!render_view_host_) { + // Bad news, the RenderViewHost got deleted while we were off running the + // menu. Nothing to do. + return; + } + + if ([menu_runner menuItemWasChosen]) { + render_view_host_->DidSelectPopupMenuItem( + [menu_runner indexOfSelectedItem]); + } else { + render_view_host_->DidCancelPopupMenu(); + } +} + +void PopupMenuHelper::Observe( + NotificationType type, + const NotificationSource& source, + const NotificationDetails& details) { + DCHECK(type == NotificationType::RENDER_WIDGET_HOST_DESTROYED); + RenderViewHost* rvh = Source<RenderViewHost>(source).ptr(); + DCHECK_EQ(render_view_host_, rvh); + render_view_host_ = NULL; +} + diff --git a/chrome/browser/tab_contents/render_view_context_menu.cc b/chrome/browser/tab_contents/render_view_context_menu.cc index 4dc7b11..989c6c9 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.cc +++ b/chrome/browser/tab_contents/render_view_context_menu.cc @@ -14,14 +14,16 @@ #include "base/stl_util-inl.h" #include "base/string_util.h" #include "base/time.h" -#include "chrome/app/chrome_dll_resource.h" +#include "chrome/app/chrome_command_ids.h" #include "chrome/browser/autocomplete/autocomplete_classifier.h" #include "chrome/browser/autocomplete/autocomplete_edit.h" +#include "chrome/browser/autocomplete/autocomplete_match.h" #include "chrome/browser/browser_process.h" #include "chrome/browser/child_process_security_policy.h" #include "chrome/browser/debugger/devtools_manager.h" #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/extensions/extension_event_router.h" #include "chrome/browser/extensions/extensions_service.h" #include "chrome/browser/fonts_languages_window.h" #include "chrome/browser/metrics/user_metrics.h" @@ -64,7 +66,7 @@ const size_t RenderViewContextMenu::kMaxSelectionTextLength = 50; // static bool RenderViewContextMenu::IsDevToolsURL(const GURL& url) { - return url.SchemeIs(chrome::kChromeUIScheme) && + return url.SchemeIs(chrome::kChromeDevToolsScheme) && url.host() == chrome::kChromeUIDevToolsHost; } @@ -149,10 +151,12 @@ static const GURL& GetDocumentURL(const ContextMenuParams& params) { } // Given a list of items, returns the ones that match given the contents -// of |params|. +// of |params| and the profile. static ExtensionMenuItem::List GetRelevantExtensionItems( const ExtensionMenuItem::List& items, - const ContextMenuParams& params) { + const ContextMenuParams& params, + Profile* profile, + bool can_cross_incognito) { ExtensionMenuItem::List result; for (ExtensionMenuItem::List::const_iterator i = items.begin(); i != items.end(); ++i) { @@ -170,7 +174,8 @@ static ExtensionMenuItem::List GetRelevantExtensionItems( if (!ExtensionPatternMatch(item->target_url_patterns(), target_url)) continue; - result.push_back(*i); + if (item->id().profile == profile || can_cross_incognito) + result.push_back(*i); } return result; } @@ -179,7 +184,8 @@ void RenderViewContextMenu::AppendExtensionItems( const std::string& extension_id, int* index) { ExtensionsService* service = profile_->GetExtensionsService(); ExtensionMenuManager* manager = service->menu_manager(); - Extension* extension = service->GetExtensionById(extension_id, false); + const Extension* extension = service->GetExtensionById(extension_id, false); + bool can_cross_incognito = service->CanCrossIncognito(extension); DCHECK_GE(*index, 0); int max_index = IDC_EXTENSIONS_CONTEXT_CUSTOM_LAST - IDC_EXTENSIONS_CONTEXT_CUSTOM_FIRST; @@ -191,7 +197,8 @@ void RenderViewContextMenu::AppendExtensionItems( if (!all_items || all_items->empty()) return; ExtensionMenuItem::List items = - GetRelevantExtensionItems(*all_items, params_); + GetRelevantExtensionItems(*all_items, params_, profile_, + can_cross_incognito); if (items.empty()) return; @@ -214,7 +221,8 @@ void RenderViewContextMenu::AppendExtensionItems( extension_item_map_[menu_id] = item->id(); title = item->TitleWithReplacement(PrintableSelectionText(), kMaxExtensionItemTitleLength); - submenu_items = GetRelevantExtensionItems(item->children(), params_); + submenu_items = GetRelevantExtensionItems(item->children(), params_, + profile_, can_cross_incognito); } // Now add our item(s) to the menu_model_. @@ -224,13 +232,15 @@ void RenderViewContextMenu::AppendExtensionItems( menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); extension_menu_models_.push_back(submenu); menu_model_.AddSubMenu(menu_id, title, submenu); - RecursivelyAppendExtensionItems(submenu_items, submenu, index); + RecursivelyAppendExtensionItems(submenu_items, can_cross_incognito, submenu, + index); } SetExtensionIcon(extension_id); } void RenderViewContextMenu::RecursivelyAppendExtensionItems( const ExtensionMenuItem::List& items, + bool can_cross_incognito, menus::SimpleMenuModel* menu_model, int *index) { string16 selection_text = PrintableSelectionText(); @@ -257,14 +267,16 @@ void RenderViewContextMenu::RecursivelyAppendExtensionItems( kMaxExtensionItemTitleLength); if (item->type() == ExtensionMenuItem::NORMAL) { ExtensionMenuItem::List children = - GetRelevantExtensionItems(item->children(), params_); + GetRelevantExtensionItems(item->children(), params_, + profile_, can_cross_incognito); if (children.size() == 0) { menu_model->AddItem(menu_id, title); } else { menus::SimpleMenuModel* submenu = new menus::SimpleMenuModel(this); extension_menu_models_.push_back(submenu); menu_model->AddSubMenu(menu_id, title, submenu); - RecursivelyAppendExtensionItems(children, submenu, index); + RecursivelyAppendExtensionItems(children, can_cross_incognito, + submenu, index); } } else if (item->type() == ExtensionMenuItem::CHECKBOX) { menu_model->AddCheckItem(menu_id, title); @@ -317,7 +329,7 @@ void RenderViewContextMenu::AppendAllExtensionItems() { std::set<std::string> ids = menu_manager->ExtensionIds(); std::vector<std::pair<std::string, std::string> > sorted_ids; for (std::set<std::string>::iterator i = ids.begin(); i != ids.end(); ++i) { - Extension* extension = service->GetExtensionById(*i, false); + const Extension* extension = service->GetExtensionById(*i, false); if (extension) sorted_ids.push_back( std::pair<std::string, std::string>(extension->name(), *i)); @@ -742,6 +754,12 @@ bool RenderViewContextMenu::IsCommandIdEnabled(int id) const { return false; } + if (id == IDC_SAVE_PAGE && + (source_tab_contents_->content_restrictions() & + CONTENT_RESTRICTION_SAVE)) { + return false; + } + // Allow Spell Check language items on sub menu for text area context menu. if ((id >= IDC_SPELLCHECK_LANGUAGES_FIRST) && (id < IDC_SPELLCHECK_LANGUAGES_LAST)) { @@ -1428,6 +1446,10 @@ bool RenderViewContextMenu::IsDevCommandEnabled(int id) const { if (IsDevToolsURL(active_entry->url()) && !command_line.HasSwitch(switches::kProcessPerTab)) return false; + // Don't enable the web inspector if the developer tools are disabled via + // the preference dev-tools-disabled. + if (profile_->GetPrefs()->GetBoolean(prefs::kDevToolsDisabled)) + return false; } return true; diff --git a/chrome/browser/tab_contents/render_view_context_menu.h b/chrome/browser/tab_contents/render_view_context_menu.h index 9fd3108..2f1a83e 100644 --- a/chrome/browser/tab_contents/render_view_context_menu.h +++ b/chrome/browser/tab_contents/render_view_context_menu.h @@ -103,6 +103,7 @@ class RenderViewContextMenu : public menus::SimpleMenuModel::Delegate { // Used for recursively adding submenus of extension items. void RecursivelyAppendExtensionItems( const std::vector<ExtensionMenuItem*>& items, + bool can_cross_incognito, menus::SimpleMenuModel* menu_model, int *index); // This will set the icon on the most recently-added item in the menu_model_. diff --git a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc index 28d2fd8..120ea9e 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_gtk.cc +++ b/chrome/browser/tab_contents/render_view_context_menu_gtk.cc @@ -7,7 +7,7 @@ #include <gtk/gtk.h> #include "base/string_util.h" -#include "chrome/app/chrome_dll_resource.h" +#include "chrome/app/chrome_command_ids.h" #include "chrome/browser/renderer_host/render_widget_host_view_gtk.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "webkit/glue/context_menu.h" diff --git a/chrome/browser/tab_contents/render_view_context_menu_mac.mm b/chrome/browser/tab_contents/render_view_context_menu_mac.mm index 1e4e4c4..2b9ca36 100644 --- a/chrome/browser/tab_contents/render_view_context_menu_mac.mm +++ b/chrome/browser/tab_contents/render_view_context_menu_mac.mm @@ -8,7 +8,7 @@ #include "base/message_loop.h" #include "base/scoped_nsobject.h" #include "base/sys_string_conversions.h" -#include "chrome/app/chrome_dll_resource.h" +#include "chrome/app/chrome_command_ids.h" #import "chrome/browser/cocoa/menu_controller.h" #include "grit/generated_resources.h" diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc index b94ab7d..15ff1ca 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.cc +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.cc @@ -35,7 +35,7 @@ RenderViewHostDelegateViewHelper::MaybeCreateBackgroundContents( int route_id, Profile* profile, SiteInstance* site, - GURL opener_url, + const GURL& opener_url, const string16& frame_name) { ExtensionsService* extensions_service = profile->GetExtensionsService(); @@ -45,7 +45,8 @@ RenderViewHostDelegateViewHelper::MaybeCreateBackgroundContents( !extensions_service->is_ready()) return NULL; - Extension* extension = extensions_service->GetExtensionByURL(opener_url); + const Extension* extension = + extensions_service->GetExtensionByURL(opener_url); if (!extension) extension = extensions_service->GetExtensionByWebExtent(opener_url); if (!extension || diff --git a/chrome/browser/tab_contents/render_view_host_delegate_helper.h b/chrome/browser/tab_contents/render_view_host_delegate_helper.h index 5afe3c7..372b234 100644 --- a/chrome/browser/tab_contents/render_view_host_delegate_helper.h +++ b/chrome/browser/tab_contents/render_view_host_delegate_helper.h @@ -76,7 +76,7 @@ class RenderViewHostDelegateViewHelper { int route_id, Profile* profile, SiteInstance* site, - GURL opener_url, + const GURL& opener_url, const string16& frame_name); // Tracks created RenderViewHost objects that have not been shown yet. diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index eb6f1c0..91995c7 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -110,6 +110,7 @@ #include "third_party/WebKit/WebKit/chromium/public/WebView.h" #include "webkit/glue/webpreferences.h" #include "webkit/glue/password_form.h" +#include "webkit/glue/plugins/plugin_list.h" // Cross-Site Navigations // @@ -167,6 +168,7 @@ const int kJavascriptMessageExpectedDelay = 1000; // The list of prefs we want to observe. const char* kPrefsToObserve[] = { prefs::kAlternateErrorPagesEnabled, + prefs::kDefaultZoomLevel, prefs::kWebKitJavaEnabled, prefs::kWebKitJavascriptEnabled, prefs::kWebKitLoadsImagesAutomatically, @@ -586,7 +588,7 @@ RenderProcessHost* TabContents::GetRenderProcessHost() const { return render_manager_.current_host()->process(); } -void TabContents::SetExtensionApp(Extension* extension) { +void TabContents::SetExtensionApp(const Extension* extension) { DCHECK(!extension || extension->GetFullLaunchURL().is_valid()); extension_app_ = extension; @@ -604,7 +606,7 @@ void TabContents::SetExtensionAppById(const std::string& extension_app_id) { ExtensionsService* extension_service = profile()->GetExtensionsService(); if (extension_service && extension_service->is_ready()) { - Extension* extension = + const Extension* extension = extension_service->GetExtensionById(extension_app_id, false); if (extension) SetExtensionApp(extension); @@ -1465,12 +1467,10 @@ void TabContents::UpdateHistoryPageTitle(const NavigationEntry& entry) { hs->SetPageTitle(entry.virtual_url(), entry.title()); } -int TabContents::GetZoomPercent(bool* enable_increment, - bool* enable_decrement) { - *enable_decrement = *enable_increment = false; +double TabContents::GetZoomLevel() const { HostZoomMap* zoom_map = profile()->GetHostZoomMap(); if (!zoom_map) - return 100; + return 0; double zoom_level; if (temporary_zoom_settings_) { @@ -1479,9 +1479,14 @@ int TabContents::GetZoomPercent(bool* enable_increment, } else { zoom_level = zoom_map->GetZoomLevel(GetURL()); } + return zoom_level; +} +int TabContents::GetZoomPercent(bool* enable_increment, + bool* enable_decrement) { + *enable_decrement = *enable_increment = false; int percent = static_cast<int>( - WebKit::WebView::zoomLevelToZoomFactor(zoom_level) * 100); + WebKit::WebView::zoomLevelToZoomFactor(GetZoomLevel()) * 100); *enable_decrement = percent > minimum_zoom_percent_; *enable_increment = percent < maximum_zoom_percent_; return percent; @@ -1759,6 +1764,10 @@ void TabContents::UpdateWebPreferences() { render_view_host()->UpdateWebPreferences(GetWebkitPrefs()); } +void TabContents::UpdateZoomLevel() { + render_view_host()->SetZoomLevel(GetZoomLevel()); +} + void TabContents::UpdateMaxPageIDIfNecessary(SiteInstance* site_instance, RenderViewHost* rvh) { // If we are creating a RVH for a restored controller, then we might @@ -2018,25 +2027,19 @@ void TabContents::OnCrashedPlugin(const FilePath& plugin_path) { DCHECK(!plugin_path.value().empty()); std::wstring plugin_name = plugin_path.ToWStringHack(); -#if defined(OS_WIN) || defined(OS_MACOSX) - scoped_ptr<FileVersionInfo> version_info( - FileVersionInfo::CreateFileVersionInfo(plugin_path)); - if (version_info.get()) { - const std::wstring& product_name = version_info->product_name(); - if (!product_name.empty()) { - plugin_name = product_name; + WebPluginInfo plugin_info; + if (NPAPI::PluginList::Singleton()->GetPluginInfoByPath( + plugin_path, &plugin_info) && + !plugin_info.name.empty()) { + plugin_name = UTF16ToWide(plugin_info.name); #if defined(OS_MACOSX) - // Many plugins on the Mac have .plugin in the actual name, which looks - // terrible, so look for that and strip it off if present. - const std::wstring plugin_extension(L".plugin"); - if (EndsWith(plugin_name, plugin_extension, true)) - plugin_name.erase(plugin_name.length() - plugin_extension.length()); + // Many plugins on the Mac have .plugin in the actual name, which looks + // terrible, so look for that and strip it off if present. + const std::wstring plugin_extension(L".plugin"); + if (EndsWith(plugin_name, plugin_extension, true)) + plugin_name.erase(plugin_name.length() - plugin_extension.length()); #endif // OS_MACOSX - } } -#else - NOTIMPLEMENTED() << " convert plugin path to plugin name"; -#endif SkBitmap* crash_icon = ResourceBundle::GetSharedInstance().GetBitmapNamed( IDR_INFOBAR_PLUGIN_CRASHED); AddInfoBar(new SimpleAlertInfoBarDelegate( @@ -2112,9 +2115,16 @@ void TabContents::OnPageTranslated(int32 page_id, Details<PageTranslatedDetails>(&details)); } -void TabContents::OnSetSuggestResult(int32 page_id, const std::string& result) { +void TabContents::OnSetSuggestions( + int32 page_id, + const std::vector<std::string>& suggestions) { + if (delegate()) + delegate()->OnSetSuggestions(page_id, suggestions); +} + +void TabContents::OnInstantSupportDetermined(int32 page_id, bool result) { if (delegate()) - delegate()->OnSetSuggestResult(page_id, result); + delegate()->OnInstantSupportDetermined(page_id, result); } void TabContents::DidStartProvisionalLoadForFrame( @@ -2238,8 +2248,19 @@ void TabContents::DidFailProvisionalLoadWithError( Details<ProvisionalLoadDetails>(&details)); } -void TabContents::DocumentLoadedInFrame() { +void TabContents::DocumentLoadedInFrame(long long frame_id) { controller_.DocumentLoadedInFrame(); + NotificationService::current()->Notify( + NotificationType::FRAME_DOM_CONTENT_LOADED, + Source<NavigationController>(&controller_), + Details<long long>(&frame_id)); +} + +void TabContents::DidFinishLoad(long long frame_id) { + NotificationService::current()->Notify( + NotificationType::FRAME_DID_FINISH_LOAD, + Source<NavigationController>(&controller_), + Details<long long>(&frame_id)); } void TabContents::OnContentSettingsAccessed(bool content_was_blocked) { @@ -2564,16 +2585,19 @@ void TabContents::UpdateTargetURL(int32 page_id, const GURL& url) { void TabContents::UpdateThumbnail(const GURL& url, const SkBitmap& bitmap, const ThumbnailScore& score) { + if (profile()->IsOffTheRecord()) + return; + // Tell History about this thumbnail if (history::TopSites::IsEnabled()) { - if (!profile()->IsOffTheRecord()) - profile()->GetTopSites()->SetPageThumbnail(url, bitmap, score); + history::TopSites* ts = profile()->GetTopSites(); + if (ts) + ts->SetPageThumbnail(url, bitmap, score); } else { - HistoryService* hs; - if (!profile()->IsOffTheRecord() && - (hs = profile()->GetHistoryService(Profile::IMPLICIT_ACCESS))) { + HistoryService* hs = + profile()->GetHistoryService(Profile::IMPLICIT_ACCESS); + if (hs) hs->SetPageThumbnail(url, bitmap, score); - } } } @@ -2878,7 +2902,8 @@ WebPreferences TabContents::GetWebkitPrefs() { // Force accelerated compositing and 2d canvas off for chrome: and // chrome-extension: pages. - if (GetURL().SchemeIs(chrome::kChromeUIScheme)) { + if (GetURL().SchemeIs(chrome::kChromeDevToolsScheme) || + GetURL().SchemeIs(chrome::kChromeUIScheme)) { web_prefs.accelerated_compositing_enabled = false; web_prefs.accelerated_2d_canvas_enabled = false; } @@ -3080,6 +3105,8 @@ void TabContents::Observe(NotificationType type, } else if ((*pref_name_in == prefs::kDefaultCharset) || StartsWithASCII(*pref_name_in, "webkit.webprefs.", true)) { UpdateWebPreferences(); + } else if (*pref_name_in == prefs::kDefaultZoomLevel) { + UpdateZoomLevel(); } else { NOTREACHED() << "unexpected pref change notification" << *pref_name_in; } @@ -3143,7 +3170,7 @@ void TabContents::Observe(NotificationType type, } } -void TabContents::UpdateExtensionAppIcon(Extension* extension) { +void TabContents::UpdateExtensionAppIcon(const Extension* extension) { extension_app_icon_.reset(); if (extension) { @@ -3160,12 +3187,12 @@ void TabContents::UpdateExtensionAppIcon(Extension* extension) { } } -Extension* TabContents::GetExtensionContaining(const GURL& url) { +const Extension* TabContents::GetExtensionContaining(const GURL& url) { ExtensionsService* extensions_service = profile()->GetExtensionsService(); if (!extensions_service) return NULL; - Extension* extension = extensions_service->GetExtensionByURL(url); + const Extension* extension = extensions_service->GetExtensionByURL(url); return extension ? extension : extensions_service->GetExtensionByWebExtent(url); } diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 9782aa4..05c3a62 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -207,6 +207,12 @@ class TabContents : public PageNavigator, RenderViewHost* render_view_host() const { return render_manager_.current_host(); } + + DOMUI* dom_ui() const { + return render_manager_.dom_ui() ? render_manager_.dom_ui() + : render_manager_.pending_dom_ui(); + } + // Returns the currently active RenderWidgetHostView. This may change over // time and can be NULL (during setup and teardown). RenderWidgetHostView* GetRenderWidgetHostView() const { @@ -232,14 +238,14 @@ class TabContents : public PageNavigator, // NOTE: this should only be manipulated before the tab is added to a browser. // TODO(sky): resolve if this is the right way to identify an app tab. If it // is, than this should be passed in the constructor. - void SetExtensionApp(Extension* extension); + void SetExtensionApp(const Extension* extension); // Convenience for setting the app extension by id. This does nothing if // |extension_app_id| is empty, or an extension can't be found given the // specified id. void SetExtensionAppById(const std::string& extension_app_id); - Extension* extension_app() const { return extension_app_; } + const Extension* extension_app() const { return extension_app_; } bool is_app() const { return extension_app_ != NULL; } // If an app extension has been explicitly set for this TabContents its icon @@ -737,6 +743,9 @@ class TabContents : public PageNavigator, // the page title and we know we want to update history. void UpdateHistoryPageTitle(const NavigationEntry& entry); + // Gets the zoom level for this tab. + double GetZoomLevel() const; + // Gets the zoom percent for this tab. int GetZoomPercent(bool* enable_increment, bool* enable_decrement); @@ -832,6 +841,9 @@ class TabContents : public PageNavigator, // Send webkit specific settings to the renderer. void UpdateWebPreferences(); + // Instruct the renderer to update the zoom level. + void UpdateZoomLevel(); + // If our controller was restored and the page id is > than the site // instance's page id, the site instances page id is updated as well as the // renderers max page id. @@ -903,7 +915,9 @@ class TabContents : public PageNavigator, const std::string& original_lang, const std::string& translated_lang, TranslateErrors::Type error_type); - virtual void OnSetSuggestResult(int32 page_id, const std::string& result); + virtual void OnSetSuggestions(int32 page_id, + const std::vector<std::string>& suggestions); + virtual void OnInstantSupportDetermined(int32 page_id, bool result); // RenderViewHostDelegate::Resource implementation. virtual void DidStartProvisionalLoadForFrame(RenderViewHost* render_view_host, @@ -931,7 +945,8 @@ class TabContents : public PageNavigator, int error_code, const GURL& url, bool showing_repost_interstitial); - virtual void DocumentLoadedInFrame(); + virtual void DocumentLoadedInFrame(long long frame_id); + virtual void DidFinishLoad(long long frame_id); // RenderViewHostDelegate implementation. virtual RenderViewHostDelegate::View* GetViewDelegate(); @@ -1068,11 +1083,11 @@ class TabContents : public PageNavigator, // App extensions related methods: // Returns the first extension whose extent contains |url|. - Extension* GetExtensionContaining(const GURL& url); + const Extension* GetExtensionContaining(const GURL& url); // Resets app_icon_ and if |extension| is non-null creates a new // ImageLoadingTracker to load the extension's image. - void UpdateExtensionAppIcon(Extension* extension); + void UpdateExtensionAppIcon(const Extension* extension); // ImageLoadingTracker::Observer. virtual void OnImageLoaded(SkBitmap* image, ExtensionResource resource, @@ -1251,7 +1266,7 @@ class TabContents : public PageNavigator, // If non-null this tab is an app tab and this is the extension the tab was // created for. - Extension* extension_app_; + const Extension* extension_app_; // Icon for extension_app_ (if non-null) or extension_for_current_page_. SkBitmap extension_app_icon_; diff --git a/chrome/browser/tab_contents/tab_contents_delegate.cc b/chrome/browser/tab_contents/tab_contents_delegate.cc index 674fd75..25fd157 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.cc +++ b/chrome/browser/tab_contents/tab_contents_delegate.cc @@ -18,7 +18,7 @@ TabContents* TabContentsDelegate::GetConstrainingContents(TabContents* source) { return source; } -bool TabContentsDelegate::ShouldFocusConstrainedWindow(TabContents* source) { +bool TabContentsDelegate::ShouldFocusConstrainedWindow() { return true; } @@ -191,8 +191,13 @@ bool TabContentsDelegate::ShouldEnablePreferredSizeNotifications() { void TabContentsDelegate::UpdatePreferredSize(const gfx::Size& pref_size) { } -void TabContentsDelegate::OnSetSuggestResult(int32 page_id, - const std::string& result) { +void TabContentsDelegate::OnSetSuggestions( + int32 page_id, + const std::vector<std::string>& suggestions) { +} + +void TabContentsDelegate::OnInstantSupportDetermined(int32 page_id, + bool result) { } void TabContentsDelegate::ContentRestrictionsChanged(TabContents* source) { diff --git a/chrome/browser/tab_contents/tab_contents_delegate.h b/chrome/browser/tab_contents/tab_contents_delegate.h index dca24b4..63ef115 100644 --- a/chrome/browser/tab_contents/tab_contents_delegate.h +++ b/chrome/browser/tab_contents/tab_contents_delegate.h @@ -7,6 +7,7 @@ #pragma once #include <string> +#include <vector> #include "base/basictypes.h" #include "chrome/browser/automation/automation_resource_routing_delegate.h" @@ -104,7 +105,7 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { virtual TabContents* GetConstrainingContents(TabContents* source); // Returns true if constrained windows should be focused. Default is true. - virtual bool ShouldFocusConstrainedWindow(TabContents* source); + virtual bool ShouldFocusConstrainedWindow(); // Invoked prior to the TabContents showing a constrained window. virtual void WillShowConstrainedWindow(TabContents* source); @@ -305,7 +306,11 @@ class TabContentsDelegate : public AutomationResourceRoutingDelegate { virtual void UpdatePreferredSize(const gfx::Size& pref_size); // Notifies the delegate that the page has a suggest result. - virtual void OnSetSuggestResult(int32 page_id, const std::string& result); + virtual void OnSetSuggestions(int32 page_id, + const std::vector<std::string>& result); + + // Notifies the delegate whether the page supports instant-style interaction. + virtual void OnInstantSupportDetermined(int32 page_id, bool result); // Notifies the delegate that the content restrictions for this tab has // changed. diff --git a/chrome/browser/tab_contents/tab_contents_view.cc b/chrome/browser/tab_contents/tab_contents_view.cc index 83eb7a4..47e71f2 100644 --- a/chrome/browser/tab_contents/tab_contents_view.cc +++ b/chrome/browser/tab_contents/tab_contents_view.cc @@ -113,10 +113,6 @@ bool TabContentsView::IsEventTracking() const { return false; } -bool TabContentsView::ShouldDrawDropShadow() { - return false; -} - TabContentsView::TabContentsView() : tab_contents_(NULL) {} void TabContentsView::HandleKeyboardEvent(const NativeWebKeyboardEvent& event) { diff --git a/chrome/browser/tab_contents/tab_contents_view.h b/chrome/browser/tab_contents/tab_contents_view.h index 4550781..c6b9a61 100644 --- a/chrome/browser/tab_contents/tab_contents_view.h +++ b/chrome/browser/tab_contents/tab_contents_view.h @@ -153,8 +153,6 @@ class TabContentsView : public RenderViewHostDelegate::View { virtual bool IsEventTracking() const; virtual void CloseTabAfterEventTracking() {} - virtual bool ShouldDrawDropShadow(); - protected: TabContentsView(); // Abstract interface. diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.cc b/chrome/browser/tab_contents/tab_contents_view_gtk.cc index 77f8aad..7ec34e4 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.cc +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.cc @@ -247,19 +247,6 @@ void TabContentsViewGtk::RestoreFocus() { SetInitialFocus(); } -bool TabContentsViewGtk::ShouldDrawDropShadow() { - GtkWindow* window = GetTopLevelNativeWindow(); - if (!window) - return false; - - BrowserWindowGtk* browser_window = - BrowserWindowGtk::GetBrowserWindowForNativeWindow(window); - if (!browser_window) - return false; - - return browser_window->ShouldDrawInfobarDropShadowOnRenderView(); -} - void TabContentsViewGtk::SetFocusedWidget(GtkWidget* widget) { focus_store_.SetWidget(widget); } @@ -311,6 +298,17 @@ void TabContentsViewGtk::ShowContextMenu(const ContextMenuParams& params) { context_menu_->Popup(point); } +void TabContentsViewGtk::ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) { + // We are not using external popup menus on Linux, they are rendered by + // WebKit. + NOTREACHED(); +} + // Render view DnD ------------------------------------------------------------- void TabContentsViewGtk::StartDragging(const WebDropData& drop_data, diff --git a/chrome/browser/tab_contents/tab_contents_view_gtk.h b/chrome/browser/tab_contents/tab_contents_view_gtk.h index 6f92a9b..9a016a1 100644 --- a/chrome/browser/tab_contents/tab_contents_view_gtk.h +++ b/chrome/browser/tab_contents/tab_contents_view_gtk.h @@ -8,6 +8,8 @@ #include <gtk/gtk.h> +#include <vector> + #include "app/gtk_signal.h" #include "base/scoped_ptr.h" #include "chrome/browser/gtk/focus_store_gtk.h" @@ -57,10 +59,15 @@ class TabContentsViewGtk : public TabContentsView, virtual void SetInitialFocus(); virtual void StoreFocus(); virtual void RestoreFocus(); - virtual bool ShouldDrawDropShadow(); // Backend implementation of RenderViewHostDelegate::View. virtual void ShowContextMenu(const ContextMenuParams& params); + virtual void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned); virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_ops, const SkBitmap& image, diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.h b/chrome/browser/tab_contents/tab_contents_view_mac.h index 63d29f3..47b88cf 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.h +++ b/chrome/browser/tab_contents/tab_contents_view_mac.h @@ -9,6 +9,7 @@ #import <Cocoa/Cocoa.h> #include <string> +#include <vector> #include "base/scoped_nsobject.h" #include "chrome/browser/cocoa/base_view.h" @@ -76,6 +77,12 @@ class TabContentsViewMac : public TabContentsView, // Backend implementation of RenderViewHostDelegate::View. virtual void ShowContextMenu(const ContextMenuParams& params); + virtual void ShowPopupMenu(const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned); virtual void StartDragging(const WebDropData& drop_data, WebKit::WebDragOperationsMask allowed_operations, const SkBitmap& image, diff --git a/chrome/browser/tab_contents/tab_contents_view_mac.mm b/chrome/browser/tab_contents/tab_contents_view_mac.mm index eb550ab..34ce802 100644 --- a/chrome/browser/tab_contents/tab_contents_view_mac.mm +++ b/chrome/browser/tab_contents/tab_contents_view_mac.mm @@ -20,6 +20,7 @@ #include "chrome/browser/renderer_host/render_view_host_factory.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" +#include "chrome/browser/tab_contents/popup_menu_helper_mac.h" #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" @@ -55,6 +56,7 @@ COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); offset:(NSPoint)offset; - (void)cancelDeferredClose; - (void)closeTabAfterEvent; +- (void)viewDidBecomeFirstResponder:(NSNotification*)notification; @end // static @@ -109,6 +111,13 @@ RenderWidgetHostView* TabContentsViewMac::CreateViewForWidget( [cocoa_view_.get() addSubview:view_view positioned:NSWindowBelow relativeTo:nil]; + // For some reason known only to Cocoa, the autorecalculation of the key view + // loop set on the window doesn't set the next key view when the subview is + // added. On 10.6 things magically work fine; on 10.5 they fail + // <http://crbug.com/61493>. Digging into Cocoa key view loop code yielded + // madness; TODO(avi,rohit): look at this again and figure out what's really + // going on. + [cocoa_view_.get() setNextKeyView:view_view]; return view; } @@ -252,6 +261,19 @@ void TabContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { menu.Init(); } +// Display a popup menu for WebKit using Cocoa widgets. +void TabContentsViewMac::ShowPopupMenu( + const gfx::Rect& bounds, + int item_height, + double item_font_size, + int selected_item, + const std::vector<WebMenuItem>& items, + bool right_aligned) { + PopupMenuHelper popup_menu_helper(tab_contents()->render_view_host()); + popup_menu_helper.ShowPopupMenu(bounds, item_height, item_font_size, + selected_item, items, right_aligned); +} + RenderWidgetHostView* TabContentsViewMac::CreateNewWidgetInternal( int route_id, WebKit::WebPopupType popup_type) { @@ -263,9 +285,6 @@ RenderWidgetHostView* TabContentsViewMac::CreateNewWidgetInternal( static_cast<RenderWidgetHostViewMac*>(widget_view); [widget_view_mac->native_view() retain]; - // |widget_view_mac| needs to know how to position itself in our view. - widget_view_mac->set_parent_view(cocoa_view_); - return widget_view; } @@ -335,6 +354,12 @@ void TabContentsViewMac::Observe(NotificationType type, // by TabContentsController, so we can't just override -viewID method to // return it. view_id_util::SetID(self, VIEW_ID_TAB_CONTAINER); + + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(viewDidBecomeFirstResponder:) + name:kViewDidBecomeFirstResponder + object:nil]; } return self; } @@ -347,6 +372,9 @@ void TabContentsViewMac::Observe(NotificationType type, // This probably isn't strictly necessary, but can't hurt. [self unregisterDraggedTypes]; + + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; } @@ -471,4 +499,19 @@ void TabContentsViewMac::Observe(NotificationType type, tabContentsView_->CloseTab(); } +- (void)viewDidBecomeFirstResponder:(NSNotification*)notification { + NSView* view = [notification object]; + if (![[self subviews] containsObject:view]) + return; + + NSSelectionDirection direction = + [[[notification userInfo] objectForKey:kSelectionDirection] + unsignedIntegerValue]; + if (direction == NSDirectSelection) + return; + + [self tabContents]-> + FocusThroughTabTraversal(direction == NSSelectingPrevious); +} + @end diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.cc b/chrome/browser/tab_contents/tab_specific_content_settings.cc index f0989a3..edafe6c 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings.cc +++ b/chrome/browser/tab_contents/tab_specific_content_settings.cc @@ -110,16 +110,15 @@ void TabSpecificContentSettings::OnCookieAccessed( void TabSpecificContentSettings::OnIndexedDBAccessed( const GURL& url, - const string16& name, const string16& description, bool blocked_by_policy) { if (blocked_by_policy) { blocked_local_shared_objects_.indexed_dbs()->AddIndexedDB( - url, name, description); + url, description); OnContentBlocked(CONTENT_SETTINGS_TYPE_COOKIES, std::string()); }else { allowed_local_shared_objects_.indexed_dbs()->AddIndexedDB( - url, name, description); + url, description); OnContentAccessed(CONTENT_SETTINGS_TYPE_COOKIES); } } diff --git a/chrome/browser/tab_contents/tab_specific_content_settings.h b/chrome/browser/tab_contents/tab_specific_content_settings.h index 7f0aac7..5cc9213 100644 --- a/chrome/browser/tab_contents/tab_specific_content_settings.h +++ b/chrome/browser/tab_contents/tab_specific_content_settings.h @@ -95,7 +95,6 @@ class TabSpecificContentSettings const std::string& cookie_line, bool blocked_by_policy); virtual void OnIndexedDBAccessed(const GURL& url, - const string16& name, const string16& description, bool blocked_by_policy); virtual void OnLocalStorageAccessed(const GURL& url, diff --git a/chrome/browser/tab_contents/view_source_uitest.cc b/chrome/browser/tab_contents/view_source_uitest.cc index 654b747..3e22b70 100644 --- a/chrome/browser/tab_contents/view_source_uitest.cc +++ b/chrome/browser/tab_contents/view_source_uitest.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/app/chrome_dll_resource.h" +#include "chrome/app/chrome_command_ids.h" #include "chrome/common/url_constants.h" #include "chrome/test/automation/browser_proxy.h" #include "chrome/test/automation/tab_proxy.h" diff --git a/chrome/browser/tab_contents/web_drag_dest_gtk.cc b/chrome/browser/tab_contents/web_drag_dest_gtk.cc index c0b3d9a..2c38987 100644 --- a/chrome/browser/tab_contents/web_drag_dest_gtk.cc +++ b/chrome/browser/tab_contents/web_drag_dest_gtk.cc @@ -14,6 +14,7 @@ #include "chrome/browser/gtk/gtk_util.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/tab_contents/tab_contents.h" +#include "chrome/common/url_constants.h" #include "net/base/net_util.h" using WebKit::WebDragOperation; @@ -169,8 +170,10 @@ void WebDragDestGtk::OnDragDataReceived( // dragging files. To avoid exposing file system paths to web content, // file URLs are never set as the URL content for the drop. // TODO(estade): Can the filenames have a non-UTF8 encoding? + GURL url(*uri_iter); FilePath file_path; - if (net::FileURLToFilePath(GURL(*uri_iter), &file_path)) { + if (url.SchemeIs(chrome::kFileScheme) && + net::FileURLToFilePath(url, &file_path)) { drop_data_->filenames.push_back(UTF8ToUTF16(file_path.value())); // This is a hack. Some file managers also populate text/plain with // a file URL when dragging files, so we clear it to avoid exposing @@ -178,7 +181,7 @@ void WebDragDestGtk::OnDragDataReceived( drop_data_->plain_text.clear(); } else if (!drop_data_->url.is_valid()) { // Also set the first non-file URL as the URL content for the drop. - drop_data_->url = GURL(*uri_iter); + drop_data_->url = url; } } g_strfreev(uris); |