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

Side by Side Diff: chrome/browser/plugins/plugin_installer.cc

Issue 11029045: Fix crash when a download is requested for an outdated plugin. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 2 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
« no previous file with comments | « chrome/browser/plugins/plugin_installer.h ('k') | chrome/browser/plugins/plugin_observer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/plugins/plugin_installer.h" 5 #include "chrome/browser/plugins/plugin_installer.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/bind_helpers.h" 8 #include "base/bind_helpers.h"
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/process.h" 10 #include "base/process.h"
(...skipping 19 matching lines...) Expand all
30 30
31 using content::BrowserContext; 31 using content::BrowserContext;
32 using content::BrowserThread; 32 using content::BrowserThread;
33 using content::DownloadItem; 33 using content::DownloadItem;
34 using content::DownloadManager; 34 using content::DownloadManager;
35 using content::ResourceDispatcherHost; 35 using content::ResourceDispatcherHost;
36 36
37 namespace { 37 namespace {
38 38
39 void BeginDownload( 39 void BeginDownload(
40 const GURL& url, 40 GURL url,
41 content::ResourceContext* resource_context, 41 content::ResourceContext* resource_context,
42 int render_process_host_id, 42 int render_process_host_id,
43 int render_view_host_routing_id, 43 int render_view_host_routing_id,
44 const ResourceDispatcherHost::DownloadStartedCallback& callback) { 44 const ResourceDispatcherHost::DownloadStartedCallback& callback) {
45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); 45 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO));
46 46
47 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get(); 47 ResourceDispatcherHost* rdh = ResourceDispatcherHost::Get();
48 scoped_ptr<net::URLRequest> request( 48 scoped_ptr<net::URLRequest> request(
49 resource_context->GetRequestContext()->CreateRequest(url, NULL)); 49 resource_context->GetRequestContext()->CreateRequest(url, NULL));
50 net::Error error = rdh->BeginDownload( 50 net::Error error = rdh->BeginDownload(
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 122
123 void PluginInstaller::AddWeakObserver(WeakPluginInstallerObserver* observer) { 123 void PluginInstaller::AddWeakObserver(WeakPluginInstallerObserver* observer) {
124 weak_observers_.AddObserver(observer); 124 weak_observers_.AddObserver(observer);
125 } 125 }
126 126
127 void PluginInstaller::RemoveWeakObserver( 127 void PluginInstaller::RemoveWeakObserver(
128 WeakPluginInstallerObserver* observer) { 128 WeakPluginInstallerObserver* observer) {
129 weak_observers_.RemoveObserver(observer); 129 weak_observers_.RemoveObserver(observer);
130 } 130 }
131 131
132 void PluginInstaller::StartInstalling(bool url_for_display, 132 void PluginInstaller::StartInstalling(GURL plugin_url,
133 const GURL& plugin_url,
134 TabContents* tab_contents) { 133 TabContents* tab_contents) {
135 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); 134 DCHECK_EQ(INSTALLER_STATE_IDLE, state_);
136 DCHECK(url_for_display);
137 state_ = INSTALLER_STATE_DOWNLOADING; 135 state_ = INSTALLER_STATE_DOWNLOADING;
138 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted()); 136 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadStarted());
139 content::WebContents* web_contents = tab_contents->web_contents(); 137 content::WebContents* web_contents = tab_contents->web_contents();
140 DownloadManager* download_manager = 138 DownloadManager* download_manager =
141 BrowserContext::GetDownloadManager(tab_contents->profile()); 139 BrowserContext::GetDownloadManager(tab_contents->profile());
142 download_util::RecordDownloadSource( 140 download_util::RecordDownloadSource(
143 download_util::INITIATED_BY_PLUGIN_INSTALLER); 141 download_util::INITIATED_BY_PLUGIN_INSTALLER);
144 BrowserThread::PostTask( 142 BrowserThread::PostTask(
145 BrowserThread::IO, FROM_HERE, 143 BrowserThread::IO, FROM_HERE,
146 base::Bind(&BeginDownload, 144 base::Bind(&BeginDownload,
(...skipping 20 matching lines...) Expand all
167 // TODO(benjhayden): DCHECK(item && item->IsInProgress()) after figuring out 165 // TODO(benjhayden): DCHECK(item && item->IsInProgress()) after figuring out
168 // why DownloadStarted may get net:OK but an invalid id. 166 // why DownloadStarted may get net:OK but an invalid id.
169 if (!download_item) { 167 if (!download_item) {
170 DownloadError("Download not found"); 168 DownloadError("Download not found");
171 return; 169 return;
172 } 170 }
173 download_item->SetOpenWhenComplete(true); 171 download_item->SetOpenWhenComplete(true);
174 download_item->AddObserver(this); 172 download_item->AddObserver(this);
175 } 173 }
176 174
177 void PluginInstaller::OpenDownloadURL(bool url_for_display, 175 void PluginInstaller::OpenDownloadURL(GURL plugin_url,
ibraaaa 2012/10/05 11:14:07 Here a copy is made directly in |OpenURLParams()|
Bernhard Bauer 2012/10/05 11:16:30 Consistency with what? Note that we usually pass o
ibraaaa 2012/10/05 11:23:36 Well I thought this way. If a refactor is done to
Bernhard Bauer 2012/10/05 12:01:57 Wait, do we know that this fixes the crash? It see
178 const GURL& plugin_url,
179 content::WebContents* web_contents) { 176 content::WebContents* web_contents) {
180 DCHECK_EQ(INSTALLER_STATE_IDLE, state_); 177 DCHECK_EQ(INSTALLER_STATE_IDLE, state_);
181 DCHECK(url_for_display);
182 web_contents->OpenURL(content::OpenURLParams( 178 web_contents->OpenURL(content::OpenURLParams(
183 plugin_url, 179 plugin_url,
184 content::Referrer(web_contents->GetURL(), 180 content::Referrer(web_contents->GetURL(),
185 WebKit::WebReferrerPolicyDefault), 181 WebKit::WebReferrerPolicyDefault),
186 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false)); 182 NEW_FOREGROUND_TAB, content::PAGE_TRANSITION_TYPED, false));
187 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished()); 183 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadFinished());
188 } 184 }
189 185
190 void PluginInstaller::DownloadError(const std::string& msg) { 186 void PluginInstaller::DownloadError(const std::string& msg) {
191 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); 187 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_);
192 state_ = INSTALLER_STATE_IDLE; 188 state_ = INSTALLER_STATE_IDLE;
193 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg)); 189 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadError(msg));
194 } 190 }
195 191
196 void PluginInstaller::DownloadCancelled() { 192 void PluginInstaller::DownloadCancelled() {
197 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_); 193 DCHECK_EQ(INSTALLER_STATE_DOWNLOADING, state_);
198 state_ = INSTALLER_STATE_IDLE; 194 state_ = INSTALLER_STATE_IDLE;
199 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled()); 195 FOR_EACH_OBSERVER(PluginInstallerObserver, observers_, DownloadCancelled());
200 } 196 }
OLDNEW
« no previous file with comments | « chrome/browser/plugins/plugin_installer.h ('k') | chrome/browser/plugins/plugin_observer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698