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

Side by Side Diff: chrome/browser/ui/apps/chrome_shell_window_delegate.cc

Issue 18051015: Use scoped_ptr for ShellWindowLinkDelegate to prevent memory leak. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 7 years, 5 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/apps/chrome_shell_window_delegate.h" 5 #include "chrome/browser/ui/apps/chrome_shell_window_delegate.h"
6 6
7 #include "base/strings/stringprintf.h" 7 #include "base/strings/stringprintf.h"
8 #include "chrome/browser/favicon/favicon_tab_helper.h" 8 #include "chrome/browser/favicon/favicon_tab_helper.h"
9 #include "chrome/browser/file_select_helper.h" 9 #include "chrome/browser/file_select_helper.h"
10 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
(...skipping 11 matching lines...) Expand all
22 #if defined(USE_ASH) 22 #if defined(USE_ASH)
23 #include "ash/launcher/launcher_types.h" 23 #include "ash/launcher/launcher_types.h"
24 #endif 24 #endif
25 25
26 namespace chrome { 26 namespace chrome {
27 27
28 namespace { 28 namespace {
29 29
30 bool disable_external_open_for_testing_ = false; 30 bool disable_external_open_for_testing_ = false;
31 31
32 class ShellWindowLinkDelegate : public content::WebContentsDelegate { 32 } // namespace
33 public:
34 ShellWindowLinkDelegate();
35
36 private:
37 virtual content::WebContents* OpenURLFromTab(
38 content::WebContents* source,
39 const content::OpenURLParams& params) OVERRIDE;
40
41 DISALLOW_COPY_AND_ASSIGN(ShellWindowLinkDelegate);
42 };
43 33
44 ShellWindowLinkDelegate::ShellWindowLinkDelegate() {} 34 ShellWindowLinkDelegate::ShellWindowLinkDelegate() {}
45 35
46 // TODO(rockot): Add a test that exercises this code. See 36 // TODO(rockot): Add a test that exercises this code. See
47 // http://crbug.com/254260. 37 // http://crbug.com/254260.
48 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab( 38 content::WebContents* ShellWindowLinkDelegate::OpenURLFromTab(
49 content::WebContents* source, 39 content::WebContents* source,
50 const content::OpenURLParams& params) { 40 const content::OpenURLParams& params) {
51 platform_util::OpenExternal(params.url); 41 platform_util::OpenExternal(params.url);
52 delete source; 42 delete source;
53 return NULL; 43 return NULL;
54 } 44 }
55 45
56 } // namespace
57
58 ChromeShellWindowDelegate::ChromeShellWindowDelegate() {} 46 ChromeShellWindowDelegate::ChromeShellWindowDelegate() {}
59 47
60 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {} 48 ChromeShellWindowDelegate::~ChromeShellWindowDelegate() {}
61 49
62 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() { 50 void ChromeShellWindowDelegate::DisableExternalOpenForTesting() {
63 disable_external_open_for_testing_ = true; 51 disable_external_open_for_testing_ = true;
64 } 52 }
65 53
66 void ChromeShellWindowDelegate::InitWebContents( 54 void ChromeShellWindowDelegate::InitWebContents(
67 content::WebContents* web_contents) { 55 content::WebContents* web_contents) {
(...skipping 17 matching lines...) Expand all
85 } 73 }
86 74
87 void ChromeShellWindowDelegate::AddNewContents( 75 void ChromeShellWindowDelegate::AddNewContents(
88 Profile* profile, 76 Profile* profile,
89 content::WebContents* new_contents, 77 content::WebContents* new_contents,
90 WindowOpenDisposition disposition, 78 WindowOpenDisposition disposition,
91 const gfx::Rect& initial_pos, 79 const gfx::Rect& initial_pos,
92 bool user_gesture, 80 bool user_gesture,
93 bool* was_blocked) { 81 bool* was_blocked) {
94 if (!disable_external_open_for_testing_) { 82 if (!disable_external_open_for_testing_) {
95 new_contents->SetDelegate(new ShellWindowLinkDelegate()); 83 if (!shell_window_link_delegate_.get())
84 shell_window_link_delegate_.reset(new ShellWindowLinkDelegate());
85 new_contents->SetDelegate(shell_window_link_delegate_.get());
sky 2013/07/08 14:51:39 What is the lifetime of new_contents?
zhchbin 2013/07/09 02:00:10 It will be deleted when the ShellWindowLinkDelegat
96 return; 86 return;
97 } 87 }
98 Browser* browser = 88 Browser* browser =
99 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop()); 89 chrome::FindOrCreateTabbedBrowser(profile, chrome::GetActiveDesktop());
100 // Force all links to open in a new tab, even if they were trying to open a 90 // Force all links to open in a new tab, even if they were trying to open a
101 // new window. 91 // new window.
102 disposition = 92 disposition =
103 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB; 93 disposition == NEW_BACKGROUND_TAB ? disposition : NEW_FOREGROUND_TAB;
104 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos, 94 chrome::AddWebContents(browser, NULL, new_contents, disposition, initial_pos,
105 user_gesture, was_blocked); 95 user_gesture, was_blocked);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 host->GetRoutingID(), blocked)); 134 host->GetRoutingID(), blocked));
145 } 135 }
146 } 136 }
147 137
148 bool ChromeShellWindowDelegate::IsWebContentsVisible( 138 bool ChromeShellWindowDelegate::IsWebContentsVisible(
149 content::WebContents* web_contents) { 139 content::WebContents* web_contents) {
150 return platform_util::IsVisible(web_contents->GetView()->GetNativeView()); 140 return platform_util::IsVisible(web_contents->GetView()->GetNativeView());
151 } 141 }
152 142
153 } // namespace chrome 143 } // namespace chrome
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698