| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 devices.push_back(iter->second[0]); | 205 devices.push_back(iter->second[0]); |
| 206 } | 206 } |
| 207 | 207 |
| 208 callback.Run(devices); | 208 callback.Run(devices); |
| 209 } | 209 } |
| 210 | 210 |
| 211 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, | 211 WebContents* ShellWindow::OpenURLFromTab(WebContents* source, |
| 212 const content::OpenURLParams& params) { | 212 const content::OpenURLParams& params) { |
| 213 DCHECK(source == web_contents_); | 213 DCHECK(source == web_contents_); |
| 214 | 214 |
| 215 if (params.url.host() == extension_->id()) { | |
| 216 AddMessageToDevToolsConsole( | |
| 217 content::CONSOLE_MESSAGE_LEVEL_ERROR, | |
| 218 base::StringPrintf( | |
| 219 "Can't navigate to \"%s\"; apps do not support navigation.", | |
| 220 params.url.spec().c_str())); | |
| 221 return NULL; | |
| 222 } | |
| 223 | |
| 224 // Don't allow the current tab to be navigated. It would be nice to map all | |
| 225 // anchor tags (even those without target="_blank") to new tabs, but right | |
| 226 // now we can't distinguish between those and <meta> refreshes, which we | |
| 227 // don't want to allow. | |
| 228 // TOOD(mihaip): Can we check for user gestures instead? | |
| 229 WindowOpenDisposition disposition = params.disposition; | 215 WindowOpenDisposition disposition = params.disposition; |
| 230 if (disposition == CURRENT_TAB) { | |
| 231 AddMessageToDevToolsConsole( | |
| 232 content::CONSOLE_MESSAGE_LEVEL_ERROR, | |
| 233 base::StringPrintf( | |
| 234 "Can't open same-window link to \"%s\"; try target=\"_blank\".", | |
| 235 params.url.spec().c_str())); | |
| 236 return NULL; | |
| 237 } | |
| 238 | |
| 239 // These dispositions aren't really navigations. | 216 // These dispositions aren't really navigations. |
| 240 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || | 217 if (disposition == SUPPRESS_OPEN || disposition == SAVE_TO_DISK || |
| 241 disposition == IGNORE_ACTION) { | 218 disposition == IGNORE_ACTION) { |
| 242 return NULL; | 219 return NULL; |
| 243 } | 220 } |
| 244 | 221 |
| 245 // Force all links to open in a new tab, even if they were trying to open a | 222 // Force all links to open in a new tab, even if they were trying to open a |
| 246 // window. | 223 // window. |
| 247 content::OpenURLParams new_tab_params = params; | 224 chrome::NavigateParams new_tab_params( |
| 225 static_cast<Browser*>(NULL), params.url, params.transition); |
| 248 new_tab_params.disposition = | 226 new_tab_params.disposition = |
| 249 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; | 227 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; |
| 250 Browser* browser = browser::FindOrCreateTabbedBrowser(profile_); | 228 new_tab_params.initiating_profile = profile_; |
| 251 WebContents* new_tab = browser->OpenURL(new_tab_params); | 229 chrome::Navigate(&new_tab_params); |
| 252 browser->window()->Show(); | 230 |
| 253 return new_tab; | 231 WebContents* new_contents = new_tab_params.target_contents ? |
| 232 new_tab_params.target_contents->web_contents() : NULL; |
| 233 if (!new_contents) { |
| 234 AddMessageToDevToolsConsole( |
| 235 content::CONSOLE_MESSAGE_LEVEL_ERROR, |
| 236 base::StringPrintf( |
| 237 "Can't navigate to \"%s\"; apps do not support navigation.", |
| 238 params.url.spec().c_str())); |
| 239 } |
| 240 |
| 241 return new_contents; |
| 254 } | 242 } |
| 255 | 243 |
| 256 void ShellWindow::AddNewContents(WebContents* source, | 244 void ShellWindow::AddNewContents(WebContents* source, |
| 257 WebContents* new_contents, | 245 WebContents* new_contents, |
| 258 WindowOpenDisposition disposition, | 246 WindowOpenDisposition disposition, |
| 259 const gfx::Rect& initial_pos, | 247 const gfx::Rect& initial_pos, |
| 260 bool user_gesture, | 248 bool user_gesture, |
| 261 bool* was_blocked) { | 249 bool* was_blocked) { |
| 262 DCHECK(source == web_contents_); | 250 DCHECK(source == web_contents_); |
| 263 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == | 251 DCHECK(Profile::FromBrowserContext(new_contents->GetBrowserContext()) == |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 return; | 435 return; |
| 448 | 436 |
| 449 extensions::ShellWindowGeometryCache* cache = | 437 extensions::ShellWindowGeometryCache* cache = |
| 450 extensions::ExtensionSystem::Get(profile())-> | 438 extensions::ExtensionSystem::Get(profile())-> |
| 451 shell_window_geometry_cache(); | 439 shell_window_geometry_cache(); |
| 452 | 440 |
| 453 gfx::Rect bounds = native_window_->GetBounds(); | 441 gfx::Rect bounds = native_window_->GetBounds(); |
| 454 cache->SaveGeometry(extension()->id(), window_key_, bounds); | 442 cache->SaveGeometry(extension()->id(), window_key_, bounds); |
| 455 } | 443 } |
| 456 | 444 |
| OLD | NEW |