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

Side by Side Diff: chrome/browser/printing/print_preview_tab_controller.cc

Issue 7649026: Print Preview: Always enable the internal PDF plugin for print preview. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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 | « no previous file | content/browser/plugin_service.h » ('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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/printing/print_preview_tab_controller.h" 5 #include "chrome/browser/printing/print_preview_tab_controller.h"
6 6
7 #include <vector>
8
7 #include "base/command_line.h" 9 #include "base/command_line.h"
10 #include "base/utf_string_conversions.h"
8 #include "chrome/browser/browser_process.h" 11 #include "chrome/browser/browser_process.h"
9 #include "chrome/browser/profiles/profile.h" 12 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/sessions/restore_tab_helper.h" 13 #include "chrome/browser/sessions/restore_tab_helper.h"
11 #include "chrome/browser/tabs/tab_strip_model.h" 14 #include "chrome/browser/tabs/tab_strip_model.h"
12 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_list.h" 16 #include "chrome/browser/ui/browser_list.h"
14 #include "chrome/browser/ui/browser_navigator.h" 17 #include "chrome/browser/ui/browser_navigator.h"
15 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 18 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
16 #include "chrome/browser/ui/webui/print_preview_ui.h" 19 #include "chrome/browser/ui/webui/print_preview_ui.h"
20 #include "chrome/common/chrome_content_client.h"
17 #include "chrome/common/chrome_switches.h" 21 #include "chrome/common/chrome_switches.h"
18 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "content/browser/plugin_service.h"
24 #include "content/browser/renderer_host/render_view_host.h"
19 #include "content/browser/tab_contents/navigation_details.h" 25 #include "content/browser/tab_contents/navigation_details.h"
20 #include "content/browser/tab_contents/tab_contents.h" 26 #include "content/browser/tab_contents/tab_contents.h"
21 #include "content/common/notification_details.h" 27 #include "content/common/notification_details.h"
22 #include "content/common/notification_source.h" 28 #include "content/common/notification_source.h"
29 #include "webkit/plugins/npapi/plugin_group.h"
30 #include "webkit/plugins/npapi/plugin_list.h"
31 #include "webkit/plugins/webplugininfo.h"
32
33 using webkit::npapi::PluginGroup;
34 using webkit::npapi::PluginList;
35 using webkit::WebPluginInfo;
36
37 namespace {
38
39 void EnableInternalPDFPluginForTab(TabContentsWrapper* preview_tab) {
40 // Always enable the internal PDF plugin for the print preview page.
41 string16 internal_pdf_group_name(
42 ASCIIToUTF16(chrome::ChromeContentClient::kPDFPluginName));
43 PluginGroup* internal_pdf_group = NULL;
44 std::vector<PluginGroup> plugin_groups;
45 PluginList::Singleton()->GetPluginGroups(false, &plugin_groups);
46 for (size_t i = 0; i < plugin_groups.size(); ++i) {
47 if (plugin_groups[i].GetGroupName() == internal_pdf_group_name) {
48 internal_pdf_group = &plugin_groups[i];
49 break;
50 }
51 }
52 if (internal_pdf_group) {
53 std::vector<WebPluginInfo> plugins = internal_pdf_group->web_plugin_infos();
54 DCHECK_EQ(plugins.size(), 1U);
55
56 PluginService::OverriddenPlugin plugin;
57 plugin.render_process_id = preview_tab->render_view_host()->process()->id();
58 plugin.render_view_id = preview_tab->render_view_host()->routing_id();
59 plugin.plugin = plugins[0];
60 plugin.plugin.enabled = WebPluginInfo::USER_ENABLED;
61
62 PluginService::GetInstance()->OverridePluginForTab(plugin);
63 }
64 }
65
66 } // namespace
23 67
24 namespace printing { 68 namespace printing {
25 69
26 PrintPreviewTabController::PrintPreviewTabController() 70 PrintPreviewTabController::PrintPreviewTabController()
27 : waiting_for_new_preview_page_(false) { 71 : waiting_for_new_preview_page_(false) {
28 } 72 }
29 73
30 PrintPreviewTabController::~PrintPreviewTabController() {} 74 PrintPreviewTabController::~PrintPreviewTabController() {}
31 75
32 // static 76 // static
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 browser::NavigateParams params(current_browser, 260 browser::NavigateParams params(current_browser,
217 GURL(chrome::kChromeUIPrintURL), 261 GURL(chrome::kChromeUIPrintURL),
218 PageTransition::LINK); 262 PageTransition::LINK);
219 params.disposition = NEW_FOREGROUND_TAB; 263 params.disposition = NEW_FOREGROUND_TAB;
220 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame)) 264 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kChromeFrame))
221 params.disposition = NEW_POPUP; 265 params.disposition = NEW_POPUP;
222 params.tabstrip_index = current_browser->tabstrip_model()-> 266 params.tabstrip_index = current_browser->tabstrip_model()->
223 GetWrapperIndex(initiator_tab) + 1; 267 GetWrapperIndex(initiator_tab) + 1;
224 browser::Navigate(&params); 268 browser::Navigate(&params);
225 TabContentsWrapper* preview_tab = params.target_contents; 269 TabContentsWrapper* preview_tab = params.target_contents;
270 EnableInternalPDFPluginForTab(preview_tab);
226 static_cast<RenderViewHostDelegate*>(preview_tab->tab_contents())->Activate(); 271 static_cast<RenderViewHostDelegate*>(preview_tab->tab_contents())->Activate();
227 272
228 // Add an entry to the map. 273 // Add an entry to the map.
229 preview_tab_map_[preview_tab->tab_contents()] = initiator_tab; 274 preview_tab_map_[preview_tab->tab_contents()] = initiator_tab;
230 waiting_for_new_preview_page_ = true; 275 waiting_for_new_preview_page_ = true;
231 276
232 AddObservers(initiator_tab); 277 AddObservers(initiator_tab);
233 AddObservers(preview_tab->tab_contents()); 278 AddObservers(preview_tab->tab_contents());
234 279
235 return preview_tab->tab_contents(); 280 return preview_tab->tab_contents();
236 } 281 }
237 282
238 void PrintPreviewTabController::AddObservers(TabContents* tab) { 283 void PrintPreviewTabController::AddObservers(TabContents* tab) {
239 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, 284 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
240 Source<TabContents>(tab)); 285 Source<TabContents>(tab));
241 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 286 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
242 Source<NavigationController>(&tab->controller())); 287 Source<NavigationController>(&tab->controller()));
243 } 288 }
244 289
245 void PrintPreviewTabController::RemoveObservers(TabContents* tab) { 290 void PrintPreviewTabController::RemoveObservers(TabContents* tab) {
246 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED, 291 registrar_.Remove(this, content::NOTIFICATION_TAB_CONTENTS_DESTROYED,
247 Source<TabContents>(tab)); 292 Source<TabContents>(tab));
248 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED, 293 registrar_.Remove(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
249 Source<NavigationController>(&tab->controller())); 294 Source<NavigationController>(&tab->controller()));
250 } 295 }
251 296
252 } // namespace printing 297 } // namespace printing
OLDNEW
« no previous file with comments | « no previous file | content/browser/plugin_service.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698