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

Side by Side Diff: chrome/browser/ui/pdf/pdf_unsupported_feature.cc

Issue 10537104: TabContentsWrapper -> TabContents, part 45. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 6 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 | Annotate | Revision Log
« no previous file with comments | « chrome/browser/ui/pdf/pdf_unsupported_feature.h ('k') | no next file » | 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/ui/pdf/pdf_unsupported_feature.h" 5 #include "chrome/browser/ui/pdf/pdf_unsupported_feature.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/utf_string_conversions.h" 8 #include "base/utf_string_conversions.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/version.h" 10 #include "base/version.h"
11 #include "chrome/browser/chrome_plugin_service_filter.h" 11 #include "chrome/browser/chrome_plugin_service_filter.h"
12 #include "chrome/browser/infobars/infobar_tab_helper.h" 12 #include "chrome/browser/infobars/infobar_tab_helper.h"
13 #include "chrome/browser/plugin_prefs.h" 13 #include "chrome/browser/plugin_prefs.h"
14 #include "chrome/browser/prefs/pref_service.h" 14 #include "chrome/browser/prefs/pref_service.h"
15 #include "chrome/browser/profiles/profile.h" 15 #include "chrome/browser/profiles/profile.h"
16 #include "chrome/browser/renderer_preferences_util.h" 16 #include "chrome/browser/renderer_preferences_util.h"
17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h" 17 #include "chrome/browser/tab_contents/confirm_infobar_delegate.h"
18 #include "chrome/browser/tab_contents/tab_util.h" 18 #include "chrome/browser/tab_contents/tab_util.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/common/chrome_content_client.h" 20 #include "chrome/common/chrome_content_client.h"
21 #include "chrome/common/jstemplate_builder.h" 21 #include "chrome/common/jstemplate_builder.h"
22 #include "chrome/common/pref_names.h" 22 #include "chrome/common/pref_names.h"
23 #include "content/public/browser/interstitial_page.h" 23 #include "content/public/browser/interstitial_page.h"
24 #include "content/public/browser/interstitial_page_delegate.h" 24 #include "content/public/browser/interstitial_page_delegate.h"
25 #include "content/public/browser/plugin_service.h" 25 #include "content/public/browser/plugin_service.h"
26 #include "content/public/browser/render_process_host.h" 26 #include "content/public/browser/render_process_host.h"
27 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
28 #include "content/public/browser/user_metrics.h" 28 #include "content/public/browser/user_metrics.h"
29 #include "content/public/browser/web_contents.h" 29 #include "content/public/browser/web_contents.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 143
144 // Launch the url to get the latest Adbobe Reader installer. 144 // Launch the url to get the latest Adbobe Reader installer.
145 void OpenReaderUpdateURL(WebContents* tab) { 145 void OpenReaderUpdateURL(WebContents* tab) {
146 OpenURLParams params( 146 OpenURLParams params(
147 GURL(kReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB, 147 GURL(kReaderUpdateUrl), Referrer(), NEW_FOREGROUND_TAB,
148 content::PAGE_TRANSITION_LINK, false); 148 content::PAGE_TRANSITION_LINK, false);
149 tab->OpenURL(params); 149 tab->OpenURL(params);
150 } 150 }
151 151
152 // Opens the PDF using Adobe Reader. 152 // Opens the PDF using Adobe Reader.
153 void OpenUsingReader(TabContentsWrapper* tab, 153 void OpenUsingReader(TabContents* tab,
154 const WebPluginInfo& reader_plugin, 154 const WebPluginInfo& reader_plugin,
155 InfoBarDelegate* old_delegate, 155 InfoBarDelegate* old_delegate,
156 InfoBarDelegate* new_delegate) { 156 InfoBarDelegate* new_delegate) {
157 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab( 157 ChromePluginServiceFilter::GetInstance()->OverridePluginForTab(
158 tab->web_contents()->GetRenderProcessHost()->GetID(), 158 tab->web_contents()->GetRenderProcessHost()->GetID(),
159 tab->web_contents()->GetRenderViewHost()->GetRoutingID(), 159 tab->web_contents()->GetRenderViewHost()->GetRoutingID(),
160 tab->web_contents()->GetURL(), 160 tab->web_contents()->GetURL(),
161 ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); 161 ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName));
162 tab->web_contents()->GetRenderViewHost()->ReloadFrame(); 162 tab->web_contents()->GetRenderViewHost()->ReloadFrame();
163 163
164 if (new_delegate) { 164 if (new_delegate) {
165 if (old_delegate) { 165 if (old_delegate) {
166 tab->infobar_tab_helper()->ReplaceInfoBar(old_delegate, new_delegate); 166 tab->infobar_tab_helper()->ReplaceInfoBar(old_delegate, new_delegate);
167 } else { 167 } else {
168 tab->infobar_tab_helper()->AddInfoBar(new_delegate); 168 tab->infobar_tab_helper()->AddInfoBar(new_delegate);
169 } 169 }
170 } 170 }
171 } 171 }
172 172
173 // An interstitial to be used when the user chooses to open a PDF using Adobe 173 // An interstitial to be used when the user chooses to open a PDF using Adobe
174 // Reader, but it is out of date. 174 // Reader, but it is out of date.
175 class PDFUnsupportedFeatureInterstitial 175 class PDFUnsupportedFeatureInterstitial
176 : public content::InterstitialPageDelegate { 176 : public content::InterstitialPageDelegate {
177 public: 177 public:
178 PDFUnsupportedFeatureInterstitial( 178 PDFUnsupportedFeatureInterstitial(
179 TabContentsWrapper* tab, 179 TabContents* tab,
180 const WebPluginInfo& reader_webplugininfo) 180 const WebPluginInfo& reader_webplugininfo)
181 : tab_contents_(tab), 181 : tab_contents_(tab),
182 reader_webplugininfo_(reader_webplugininfo) { 182 reader_webplugininfo_(reader_webplugininfo) {
183 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown")); 183 content::RecordAction(UserMetricsAction("PDF_ReaderInterstitialShown"));
184 interstitial_page_ = InterstitialPage::Create( 184 interstitial_page_ = InterstitialPage::Create(
185 tab->web_contents(), false, tab->web_contents()->GetURL(), this); 185 tab->web_contents(), false, tab->web_contents()->GetURL(), this);
186 interstitial_page_->Show(); 186 interstitial_page_->Show();
187 } 187 }
188 188
189 protected: 189 protected:
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 interstitial_page_->Proceed(); 239 interstitial_page_->Proceed();
240 } 240 }
241 241
242 virtual void OverrideRendererPrefs( 242 virtual void OverrideRendererPrefs(
243 content::RendererPreferences* prefs) OVERRIDE { 243 content::RendererPreferences* prefs) OVERRIDE {
244 renderer_preferences_util::UpdateFromSystemSettings( 244 renderer_preferences_util::UpdateFromSystemSettings(
245 prefs, tab_contents_->profile()); 245 prefs, tab_contents_->profile());
246 } 246 }
247 247
248 private: 248 private:
249 TabContentsWrapper* tab_contents_; 249 TabContents* tab_contents_;
250 WebPluginInfo reader_webplugininfo_; 250 WebPluginInfo reader_webplugininfo_;
251 InterstitialPage* interstitial_page_; // Owns us. 251 InterstitialPage* interstitial_page_; // Owns us.
252 252
253 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial); 253 DISALLOW_COPY_AND_ASSIGN(PDFUnsupportedFeatureInterstitial);
254 }; 254 };
255 255
256 // The info bar delegate used to inform the user that we don't support a feature 256 // The info bar delegate used to inform the user that we don't support a feature
257 // in the PDF. See the comment about how we swap buttons for 257 // in the PDF. See the comment about how we swap buttons for
258 // PDFEnableAdobeReaderInfoBarDelegate. 258 // PDFEnableAdobeReaderInfoBarDelegate.
259 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate { 259 class PDFUnsupportedFeatureInfoBarDelegate : public ConfirmInfoBarDelegate {
260 public: 260 public:
261 // |reader| is NULL if Adobe Reader isn't installed. 261 // |reader| is NULL if Adobe Reader isn't installed.
262 PDFUnsupportedFeatureInfoBarDelegate(TabContentsWrapper* tab_contents, 262 PDFUnsupportedFeatureInfoBarDelegate(TabContents* tab_contents,
263 const webkit::WebPluginInfo* reader, 263 const webkit::WebPluginInfo* reader,
264 PluginFinder* plugin_finder); 264 PluginFinder* plugin_finder);
265 virtual ~PDFUnsupportedFeatureInfoBarDelegate(); 265 virtual ~PDFUnsupportedFeatureInfoBarDelegate();
266 266
267 // ConfirmInfoBarDelegate 267 // ConfirmInfoBarDelegate
268 virtual void InfoBarDismissed() OVERRIDE; 268 virtual void InfoBarDismissed() OVERRIDE;
269 virtual gfx::Image* GetIcon() const OVERRIDE; 269 virtual gfx::Image* GetIcon() const OVERRIDE;
270 virtual Type GetInfoBarType() const OVERRIDE; 270 virtual Type GetInfoBarType() const OVERRIDE;
271 virtual bool Accept() OVERRIDE; 271 virtual bool Accept() OVERRIDE;
272 virtual bool Cancel() OVERRIDE; 272 virtual bool Cancel() OVERRIDE;
273 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE; 273 virtual string16 GetButtonLabel(InfoBarButton button) const OVERRIDE;
274 virtual string16 GetMessageText() const OVERRIDE; 274 virtual string16 GetMessageText() const OVERRIDE;
275 275
276 private: 276 private:
277 bool OnYes(); 277 bool OnYes();
278 void OnNo(); 278 void OnNo();
279 279
280 TabContentsWrapper* tab_contents_; 280 TabContents* tab_contents_;
281 bool reader_installed_; 281 bool reader_installed_;
282 bool reader_vulnerable_; 282 bool reader_vulnerable_;
283 WebPluginInfo reader_webplugininfo_; 283 WebPluginInfo reader_webplugininfo_;
284 284
285 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate); 285 DISALLOW_IMPLICIT_CONSTRUCTORS(PDFUnsupportedFeatureInfoBarDelegate);
286 }; 286 };
287 287
288 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate( 288 PDFUnsupportedFeatureInfoBarDelegate::PDFUnsupportedFeatureInfoBarDelegate(
289 TabContentsWrapper* tab_contents, 289 TabContents* tab_contents,
290 const webkit::WebPluginInfo* reader, 290 const webkit::WebPluginInfo* reader,
291 PluginFinder* plugin_finder) 291 PluginFinder* plugin_finder)
292 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()), 292 : ConfirmInfoBarDelegate(tab_contents->infobar_tab_helper()),
293 tab_contents_(tab_contents), 293 tab_contents_(tab_contents),
294 reader_installed_(!!reader), 294 reader_installed_(!!reader),
295 reader_vulnerable_(false) { 295 reader_vulnerable_(false) {
296 if (!reader_installed_) { 296 if (!reader_installed_) {
297 content::RecordAction( 297 content::RecordAction(
298 UserMetricsAction("PDF_InstallReaderInfoBarShown")); 298 UserMetricsAction("PDF_InstallReaderInfoBarShown"));
299 return; 299 return;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 387
388 void GotPluginGroupsCallback(int process_id, 388 void GotPluginGroupsCallback(int process_id,
389 int routing_id, 389 int routing_id,
390 PluginFinder* plugin_finder, 390 PluginFinder* plugin_finder,
391 const std::vector<PluginGroup>& groups) { 391 const std::vector<PluginGroup>& groups) {
392 WebContents* web_contents = 392 WebContents* web_contents =
393 tab_util::GetWebContentsByID(process_id, routing_id); 393 tab_util::GetWebContentsByID(process_id, routing_id);
394 if (!web_contents) 394 if (!web_contents)
395 return; 395 return;
396 396
397 TabContentsWrapper* tab = 397 TabContents* tab = TabContents::FromWebContents(web_contents);
398 TabContentsWrapper::GetCurrentWrapperForContents(web_contents);
399 if (!tab) 398 if (!tab)
400 return; 399 return;
401 400
402 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName)); 401 string16 reader_group_name(ASCIIToUTF16(PluginGroup::kAdobeReaderGroupName));
403 // If the Reader plugin is disabled by policy, don't prompt them. 402 // If the Reader plugin is disabled by policy, don't prompt them.
404 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile()); 403 PluginPrefs* plugin_prefs = PluginPrefs::GetForProfile(tab->profile());
405 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) == 404 if (plugin_prefs->PolicyStatusForPlugin(reader_group_name) ==
406 PluginPrefs::POLICY_DISABLED) { 405 PluginPrefs::POLICY_DISABLED) {
407 return; 406 return;
408 } 407 }
(...skipping 16 matching lines...) Expand all
425 void GotPluginFinderCallback(int process_id, 424 void GotPluginFinderCallback(int process_id,
426 int routing_id, 425 int routing_id,
427 PluginFinder* plugin_finder) { 426 PluginFinder* plugin_finder) {
428 PluginService::GetInstance()->GetPluginGroups( 427 PluginService::GetInstance()->GetPluginGroups(
429 base::Bind(&GotPluginGroupsCallback, process_id, routing_id, 428 base::Bind(&GotPluginGroupsCallback, process_id, routing_id,
430 base::Unretained(plugin_finder))); 429 base::Unretained(plugin_finder)));
431 } 430 }
432 431
433 } // namespace 432 } // namespace
434 433
435 void PDFHasUnsupportedFeature(TabContentsWrapper* tab) { 434 void PDFHasUnsupportedFeature(TabContents* tab) {
436 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION) 435 #if defined(OS_WIN) && defined(ENABLE_PLUGIN_INSTALLATION)
437 // Only works for Windows for now. For Mac, we'll have to launch the file 436 // Only works for Windows for now. For Mac, we'll have to launch the file
438 // externally since Adobe Reader doesn't work inside Chrome. 437 // externally since Adobe Reader doesn't work inside Chrome.
439 PluginFinder::Get(base::Bind(&GotPluginFinderCallback, 438 PluginFinder::Get(base::Bind(&GotPluginFinderCallback,
440 tab->web_contents()->GetRenderProcessHost()->GetID(), 439 tab->web_contents()->GetRenderProcessHost()->GetID(),
441 tab->web_contents()->GetRenderViewHost()->GetRoutingID())); 440 tab->web_contents()->GetRenderViewHost()->GetRoutingID()));
442 #endif 441 #endif
443 } 442 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/pdf/pdf_unsupported_feature.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698