• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #include "chrome/browser/extensions/extension_clipboard_api.h"
6 
7 #include "base/string_number_conversions.h"
8 #include "base/values.h"
9 #include "chrome/browser/extensions/extension_tabs_module.h"
10 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
11 #include "chrome/common/extensions/extension_error_utils.h"
12 #include "content/browser/renderer_host/render_view_host.h"
13 #include "content/browser/tab_contents/tab_contents.h"
14 
15 namespace {
16 // Errors.
17 const char kNoTabError[] = "No tab with id: *.";
18 }
19 
RunImpl()20 bool ClipboardFunction::RunImpl() {
21   int tab_id;
22   EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id));
23 
24   TabContentsWrapper* contents = NULL;
25   if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(),
26                                     NULL, NULL, &contents, NULL)) {
27     error_ = ExtensionErrorUtils::FormatErrorMessage(
28         kNoTabError, base::IntToString(tab_id));
29     return false;
30   }
31 
32   RenderViewHost* render_view_host = contents->render_view_host();
33   if (!render_view_host) {
34     return false;
35   }
36 
37   return RunImpl(render_view_host);
38 }
39 
RunImpl(RenderViewHost * render_view_host)40 bool ExecuteCopyClipboardFunction::RunImpl(RenderViewHost* render_view_host) {
41   render_view_host->Copy();
42   return true;
43 }
44 
RunImpl(RenderViewHost * render_view_host)45 bool ExecuteCutClipboardFunction::RunImpl(RenderViewHost* render_view_host) {
46   render_view_host->Cut();
47   return true;
48 }
49 
RunImpl(RenderViewHost * render_view_host)50 bool ExecutePasteClipboardFunction::RunImpl(RenderViewHost* render_view_host) {
51   render_view_host->Paste();
52   return true;
53 }
54