| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/intents/web_intent_inline_disposition_delegate.h" | |
| 6 | |
| 7 #include "base/logging.h" | |
| 8 #include "chrome/browser/ui/browser.h" | |
| 9 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 10 #include "chrome/browser/ui/intents/web_intent_picker.h" | |
| 11 #include "chrome/common/extensions/extension_messages.h" | |
| 12 #include "content/public/browser/navigation_controller.h" | |
| 13 #include "content/public/browser/render_view_host.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/common/renderer_preferences.h" | |
| 16 #include "ipc/ipc_message_macros.h" | |
| 17 | |
| 18 WebIntentInlineDispositionDelegate::WebIntentInlineDispositionDelegate( | |
| 19 WebIntentPicker* picker, | |
| 20 content::WebContents* contents, | |
| 21 Browser* browser) | |
| 22 : picker_(picker), | |
| 23 web_contents_(contents), | |
| 24 browser_(browser), | |
| 25 ALLOW_THIS_IN_INITIALIZER_LIST( | |
| 26 extension_function_dispatcher_(browser->profile(), this)) { | |
| 27 content::WebContentsObserver::Observe(web_contents_); | |
| 28 web_contents_->SetDelegate(this); | |
| 29 // TODO(groby): Technically, allowing the browser to hande all requests | |
| 30 // should work just fine. Practically, we're getting a cross-origin warning | |
| 31 // for a googleapis request. | |
| 32 // Investigate why OpenURLFromTab delegate misfires on this. | |
| 33 // web_contents_->GetMutableRendererPrefs()->browser_handles_all_requests = | |
| 34 // true; | |
| 35 } | |
| 36 | |
| 37 WebIntentInlineDispositionDelegate::~WebIntentInlineDispositionDelegate() { | |
| 38 } | |
| 39 | |
| 40 bool WebIntentInlineDispositionDelegate::IsPopupOrPanel( | |
| 41 const content::WebContents* source) const { | |
| 42 return true; | |
| 43 } | |
| 44 | |
| 45 content::WebContents* WebIntentInlineDispositionDelegate::OpenURLFromTab( | |
| 46 content::WebContents* source, const content::OpenURLParams& params) { | |
| 47 DCHECK(source); // Can only be invoked from inline disposition. | |
| 48 | |
| 49 // Load in place. | |
| 50 source->GetController().LoadURL(params.url, content::Referrer(), | |
| 51 content::PAGE_TRANSITION_AUTO_TOPLEVEL, std::string()); | |
| 52 | |
| 53 // Remove previous history entries - users should not navigate in intents. | |
| 54 source->GetController().PruneAllButActive(); | |
| 55 | |
| 56 return source; | |
| 57 } | |
| 58 | |
| 59 void WebIntentInlineDispositionDelegate::AddNewContents( | |
| 60 content::WebContents* source, | |
| 61 content::WebContents* new_contents, | |
| 62 WindowOpenDisposition disposition, | |
| 63 const gfx::Rect& initial_pos, | |
| 64 bool user_gesture, | |
| 65 bool* was_blocked) { | |
| 66 DCHECK_EQ(source, web_contents_); | |
| 67 DCHECK_EQ(Profile::FromBrowserContext(new_contents->GetBrowserContext()), | |
| 68 browser_->profile()); | |
| 69 // Force all links to open in a new tab, even when different disposition is | |
| 70 // requested. | |
| 71 disposition = | |
| 72 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | |
| 73 chrome::AddWebContents(browser_, NULL, new_contents, disposition, initial_pos, | |
| 74 user_gesture, was_blocked); | |
| 75 } | |
| 76 | |
| 77 void WebIntentInlineDispositionDelegate::LoadingStateChanged( | |
| 78 content::WebContents* source) { | |
| 79 if (!source->IsLoading()) | |
| 80 picker_->OnInlineDispositionWebContentsLoaded(source); | |
| 81 } | |
| 82 | |
| 83 bool WebIntentInlineDispositionDelegate::OnMessageReceived( | |
| 84 const IPC::Message& message) { | |
| 85 bool handled = true; | |
| 86 IPC_BEGIN_MESSAGE_MAP(WebIntentInlineDispositionDelegate, message) | |
| 87 IPC_MESSAGE_HANDLER(ExtensionHostMsg_Request, OnRequest) | |
| 88 IPC_MESSAGE_UNHANDLED(handled = false) | |
| 89 IPC_END_MESSAGE_MAP() | |
| 90 return handled; | |
| 91 } | |
| 92 | |
| 93 void WebIntentInlineDispositionDelegate::RenderViewCreated( | |
| 94 content::RenderViewHost* render_view_host) { | |
| 95 render_view_host_ = render_view_host; | |
| 96 SetRenderViewSizeLimits(); | |
| 97 } | |
| 98 | |
| 99 void WebIntentInlineDispositionDelegate::DocumentAvailableInMainFrame() { | |
| 100 std::string css = "body { min-width:400px; }"; | |
| 101 render_view_host_->InsertCSS(string16(), css); | |
| 102 } | |
| 103 | |
| 104 content::WebContents* WebIntentInlineDispositionDelegate:: | |
| 105 GetAssociatedWebContents() const { | |
| 106 return NULL; | |
| 107 } | |
| 108 | |
| 109 extensions::WindowController* | |
| 110 WebIntentInlineDispositionDelegate::GetExtensionWindowController() const { | |
| 111 return NULL; | |
| 112 } | |
| 113 | |
| 114 void WebIntentInlineDispositionDelegate::OnRequest( | |
| 115 const ExtensionHostMsg_Request_Params& params) { | |
| 116 extension_function_dispatcher_.Dispatch(params, | |
| 117 web_contents_->GetRenderViewHost()); | |
| 118 } | |
| 119 | |
| 120 void WebIntentInlineDispositionDelegate::ResizeDueToAutoResize( | |
| 121 content::WebContents* source, const gfx::Size& pref_size) { | |
| 122 DCHECK(picker_); | |
| 123 picker_->OnInlineDispositionAutoResize(pref_size); | |
| 124 } | |
| 125 | |
| 126 void WebIntentInlineDispositionDelegate::HandleKeyboardEvent( | |
| 127 content::WebContents* source, | |
| 128 const content::NativeWebKeyboardEvent& event) { | |
| 129 picker_->OnInlineDispositionHandleKeyboardEvent(event); | |
| 130 } | |
| 131 | |
| 132 void WebIntentInlineDispositionDelegate::SetRenderViewSizeLimits() { | |
| 133 render_view_host_->EnableAutoResize( | |
| 134 picker_->GetMinInlineDispositionSize(), | |
| 135 picker_->GetMaxInlineDispositionSize()); | |
| 136 } | |
| OLD | NEW |