| OLD | NEW |
| 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/ui/extensions/shell_window.h" | 5 #include "chrome/browser/ui/extensions/shell_window.h" |
| 6 | 6 |
| 7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
| 9 #include "chrome/browser/extensions/extension_system.h" | 9 #include "chrome/browser/extensions/extension_system.h" |
| 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" | 10 #include "chrome/browser/extensions/shell_window_geometry_cache.h" |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 124 if (params.restore_position) | 124 if (params.restore_position) |
| 125 bounds.set_origin(cached_bounds.origin()); | 125 bounds.set_origin(cached_bounds.origin()); |
| 126 if (params.restore_size) | 126 if (params.restore_size) |
| 127 bounds.set_size(cached_bounds.size()); | 127 bounds.set_size(cached_bounds.size()); |
| 128 | 128 |
| 129 native_window_->SetBounds(bounds); | 129 native_window_->SetBounds(bounds); |
| 130 } | 130 } |
| 131 } | 131 } |
| 132 } | 132 } |
| 133 | 133 |
| 134 | |
| 135 // Block the created RVH from loading anything until the background page | 134 // Block the created RVH from loading anything until the background page |
| 136 // has had a chance to do any initialization it wants. | 135 // has had a chance to do any initialization it wants. |
| 137 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); | 136 SuspendRenderViewHost(web_contents_->GetRenderViewHost()); |
| 138 | 137 |
| 139 // TODO(jeremya): there's a bug where navigating a web contents to an | 138 // TODO(jeremya): there's a bug where navigating a web contents to an |
| 140 // extension URL causes it to create a new RVH and discard the old (perfectly | 139 // extension URL causes it to create a new RVH and discard the old (perfectly |
| 141 // usable) one. To work around this, we watch for a RVH_CHANGED message from | 140 // usable) one. To work around this, we watch for a RVH_CHANGED message from |
| 142 // the web contents (which will be sent during LoadURL) and suspend resource | 141 // the web contents (which will be sent during LoadURL) and suspend resource |
| 143 // requests on the new RVH to ensure that we block the new RVH from loading | 142 // requests on the new RVH to ensure that we block the new RVH from loading |
| 144 // anything. It should be okay to remove the NOTIFICATION_RVH_CHANGED | 143 // anything. It should be okay to remove the NOTIFICATION_RVH_CHANGED |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 207 } | 206 } |
| 208 } | 207 } |
| 209 | 208 |
| 210 callback.Run(devices); | 209 callback.Run(devices); |
| 211 } | 210 } |
| 212 | 211 |
| 213 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, | 212 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, |
| 214 const content::OpenURLParams& params) { | 213 const content::OpenURLParams& params) { |
| 215 DCHECK(source == web_contents_); | 214 DCHECK(source == web_contents_); |
| 216 | 215 |
| 217 if (params.url.host() == extension_->id()) { | |
| 218 AddMessageToDevToolsConsole( | |
| 219 content::CONSOLE_MESSAGE_LEVEL_ERROR, | |
| 220 base::StringPrintf( | |
| 221 "Can't navigate to \"%s\"; apps do not support navigation.", | |
| 222 params.url.spec().c_str())); | |
| 223 return NULL; | |
| 224 } | |
| 225 | |
| 226 // Don't allow the current tab to be navigated. It would be nice to map all | 216 // Don't allow the current tab to be navigated. It would be nice to map all |
| 227 // anchor tags (even those without target="_blank") to new tabs, but right | 217 // anchor tags (even those without target="_blank") to new tabs, but right |
| 228 // now we can't distinguish between those and <meta> refreshes, which we | 218 // now we can't distinguish between those and <meta> refreshes or window.href |
| 229 // don't want to allow. | 219 // navigations, which we don't want to allow. |
| 230 // TOOD(mihaip): Can we check for user gestures instead? | 220 // TOOD(mihaip): Can we check for user gestures instead? |
| 231 WindowOpenDisposition disposition = params.disposition; | 221 WindowOpenDisposition disposition = params.disposition; |
| 232 if (disposition == CURRENT_TAB) { | 222 if (disposition == CURRENT_TAB) { |
| 233 AddMessageToDevToolsConsole( | 223 AddMessageToDevToolsConsole( |
| 234 content::CONSOLE_MESSAGE_LEVEL_ERROR, | 224 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 235 base::StringPrintf( | 225 base::StringPrintf( |
| 236 "Can't open same-window link to \"%s\"; try target=\"_blank\".", | 226 "Can't open same-window link to \"%s\"; try target=\"_blank\".", |
| 237 params.url.spec().c_str())); | 227 params.url.spec().c_str())); |
| 238 return NULL; | 228 return NULL; |
| 239 } | 229 } |
| 240 | 230 |
| 241 // These dispositions aren't really navigations. | 231 // These dispositions aren't really navigations. |
| 242 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || | 232 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
| 243 disposition == IGNORE_ACTION) { | 233 disposition == IGNORE_ACTION) { |
| 244 return NULL; | 234 return NULL; |
| 245 } | 235 } |
| 246 | 236 |
| 247 // Force all links to open in a new tab, even if they were trying to open a | 237 // Force all links to open in a new tab, even if they were trying to open a |
| 248 // window. | 238 // window. |
| 249 content::OpenURLParams new_tab_params = params; | 239 chrome::NavigateParams new_tab_params( |
| 240 static_cast<Browser*>(NULL), params.url, params.transition); |
| 250 new_tab_params.disposition = | 241 new_tab_params.disposition = |
| 251 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 242 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 252 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); | 243 new_tab_params.initiating_profile = profile_; |
| 253 WebContents* new_tab = browser->OpenURL(new_tab_params); | 244 chrome::Navigate(&new_tab_params); |
| 254 browser->window()->Show(); | 245 |
| 255 return new_tab; | 246 WebContents* new_contents = new_tab_params.target_contents ? |
| 247 new_tab_params.target_contents->web_contents() : NULL; |
| 248 if (!new_contents) { |
| 249 AddMessageToDevToolsConsole( |
| 250 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 251 base::StringPrintf( |
| 252 "Can't navigate to \"%s\"; apps do not support navigation.", |
| 253 params.url.spec().c_str())); |
| 254 } |
| 255 |
| 256 return new_contents; |
| 256 } | 257 } |
| 257 | 258 |
| 258 void ShellWindow::AddNewContents(WebContents* source, | 259 void ShellWindow::AddNewContents(WebContents* source, |
| 259 WebContents* new_contents, | 260 WebContents* new_contents, |
| 260 WindowOpenDisposition disposition, | 261 WindowOpenDisposition disposition, |
| 261 const gfx::Rect& initial_pos, | 262 const gfx::Rect& initial_pos, |
| 262 bool user_gesture, | 263 bool user_gesture, |
| 263 bool* was_blocked) { | 264 bool* was_blocked) { |
| 264 DCHECK(source == web_contents_); | 265 DCHECK(source == web_contents_); |
| 265 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 266 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 455 if (window_key_.empty()) | 456 if (window_key_.empty()) |
| 456 return; | 457 return; |
| 457 | 458 |
| 458 extensions::ShellWindowGeometryCache* cache = | 459 extensions::ShellWindowGeometryCache* cache = |
| 459 extensions::ExtensionSystem::Get(profile())-> | 460 extensions::ExtensionSystem::Get(profile())-> |
| 460 shell_window_geometry_cache(); | 461 shell_window_geometry_cache(); |
| 461 | 462 |
| 462 gfx::Rect bounds = native_window_->GetBounds(); | 463 gfx::Rect bounds = native_window_->GetBounds(); |
| 463 cache->SaveGeometry(extension()->id(), window_key_, bounds); | 464 cache->SaveGeometry(extension()->id(), window_key_, bounds); |
| 464 } | 465 } |
| OLD | NEW |