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

Side by Side Diff: chrome/browser/resource_message_filter.cc

Issue 19733: Make sure that Clipboard operations that require dispatching... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 10 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
« base/clipboard.h ('K') | « base/file_util_unittest.cc ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/resource_message_filter.h" 5 #include "chrome/browser/resource_message_filter.h"
6 6
7 #include "base/clipboard.h" 7 #include "base/clipboard.h"
8 #include "base/gfx/native_widget_types.h" 8 #include "base/gfx/native_widget_types.h"
9 #include "base/histogram.h" 9 #include "base/histogram.h"
10 #include "base/thread.h" 10 #include "base/thread.h"
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
55 host->OnMessageReceived(context_menu_message_); 55 host->OnMessageReceived(context_menu_message_);
56 } 56 }
57 57
58 private: 58 private:
59 int render_process_host_id_; 59 int render_process_host_id_;
60 const ViewHostMsg_ContextMenu context_menu_message_; 60 const ViewHostMsg_ContextMenu context_menu_message_;
61 61
62 DISALLOW_COPY_AND_ASSIGN(ContextMenuMessageDispatcher); 62 DISALLOW_COPY_AND_ASSIGN(ContextMenuMessageDispatcher);
63 }; 63 };
64 64
65 // Completes a clipboard write initiated by the renderer. The write must be
66 // performed on the UI thread because the clipboard service from the IO thread
67 // cannot create windows so it cannot be the "owner" of the clipboard's
68 // contents.
69 class WriteClipboardTask : public Task {
70 public:
71 explicit WriteClipboardTask(Clipboard::ObjectMap* objects)
72 : objects_(objects) {}
73 ~WriteClipboardTask() {}
74
75 void Run() {
76 g_browser_process->clipboard_service()->WriteObjects(*objects_.get());
77 }
78
79 private:
80 scoped_ptr<Clipboard::ObjectMap> objects_;
81 };
82
83
65 } // namespace 84 } // namespace
66 85
67 ResourceMessageFilter::ResourceMessageFilter( 86 ResourceMessageFilter::ResourceMessageFilter(
68 ResourceDispatcherHost* resource_dispatcher_host, 87 ResourceDispatcherHost* resource_dispatcher_host,
69 PluginService* plugin_service, 88 PluginService* plugin_service,
70 printing::PrintJobManager* print_job_manager, 89 printing::PrintJobManager* print_job_manager,
71 int render_process_host_id, 90 int render_process_host_id,
72 Profile* profile, 91 Profile* profile,
73 RenderWidgetHelper* render_widget_helper, 92 RenderWidgetHelper* render_widget_helper,
74 SpellChecker* spellchecker) 93 SpellChecker* spellchecker)
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
438 const GURL& referrer) { 457 const GURL& referrer) {
439 resource_dispatcher_host_->BeginDownload(url, 458 resource_dispatcher_host_->BeginDownload(url,
440 referrer, 459 referrer,
441 render_process_host_id_, 460 render_process_host_id_,
442 message.routing_id(), 461 message.routing_id(),
443 request_context_); 462 request_context_);
444 } 463 }
445 464
446 void ResourceMessageFilter::OnClipboardWriteObjects( 465 void ResourceMessageFilter::OnClipboardWriteObjects(
447 const Clipboard::ObjectMap& objects) { 466 const Clipboard::ObjectMap& objects) {
467 // We cannot write directly from the IO thread, and cannot service the IPC
468 // on the UI thread. We'll copy the relevant data and get a handle to any
469 // shared memory so it doesn't go away when we resume the renderer, and post
470 // a task to perform the write on the UI thread.
471 Clipboard::ObjectMap* long_living_objects = new Clipboard::ObjectMap(objects);
472
448 // We pass the render_handle_ to assist the clipboard with using shared 473 // We pass the render_handle_ to assist the clipboard with using shared
449 // memory objects. render_handle_ is a handle to the process that would 474 // memory objects. render_handle_ is a handle to the process that would
450 // own any shared memory that might be in the object list. 475 // own any shared memory that might be in the object list.
451 GetClipboardService()->WriteObjects(objects, render_handle_); 476 Clipboard::DuplicateRemoteHandles(render_handle_, long_living_objects);
477
478 render_widget_helper_->ui_loop()->PostTask(FROM_HERE,
479 new WriteClipboardTask(long_living_objects));
452 } 480 }
453 481
454 void ResourceMessageFilter::OnClipboardIsFormatAvailable(unsigned int format, 482 void ResourceMessageFilter::OnClipboardIsFormatAvailable(unsigned int format,
455 bool* result) { 483 bool* result) {
456 DCHECK(result); 484 DCHECK(result);
457 *result = GetClipboardService()->IsFormatAvailable(format); 485 *result = GetClipboardService()->IsFormatAvailable(format);
458 } 486 }
459 487
460 void ResourceMessageFilter::OnClipboardReadText(std::wstring* result) { 488 void ResourceMessageFilter::OnClipboardReadText(std::wstring* result) {
461 GetClipboardService()->ReadText(result); 489 GetClipboardService()->ReadText(result);
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
686 if (type == NOTIFY_SPELLCHECKER_REINITIALIZED) { 714 if (type == NOTIFY_SPELLCHECKER_REINITIALIZED) {
687 spellchecker_ = Details<SpellcheckerReinitializedDetails> 715 spellchecker_ = Details<SpellcheckerReinitializedDetails>
688 (details).ptr()->spellchecker; 716 (details).ptr()->spellchecker;
689 } 717 }
690 } 718 }
691 719
692 void ResourceMessageFilter::OnDnsPrefetch( 720 void ResourceMessageFilter::OnDnsPrefetch(
693 const std::vector<std::string>& hostnames) { 721 const std::vector<std::string>& hostnames) {
694 chrome_browser_net::DnsPrefetchList(hostnames); 722 chrome_browser_net::DnsPrefetchList(hostnames);
695 } 723 }
OLDNEW
« base/clipboard.h ('K') | « base/file_util_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698