OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 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/extensions/extension_clipboard_api.h" | 5 #include "chrome/browser/extensions/extension_clipboard_api.h" |
6 | 6 |
7 #include "base/string_util.h" | 7 #include "base/string_number_conversions.h" |
8 #include "base/values.h" | 8 #include "base/values.h" |
9 #include "chrome/browser/extensions/extension_tabs_module.h" | 9 #include "chrome/browser/extensions/extension_tabs_module.h" |
10 #include "chrome/browser/renderer_host/render_view_host.h" | 10 #include "chrome/browser/renderer_host/render_view_host.h" |
11 #include "chrome/browser/tab_contents/tab_contents.h" | 11 #include "chrome/browser/tab_contents/tab_contents.h" |
12 #include "chrome/common/extensions/extension_error_utils.h" | 12 #include "chrome/common/extensions/extension_error_utils.h" |
13 | 13 |
14 namespace { | 14 namespace { |
15 // Errors. | 15 // Errors. |
16 const char kNoTabError[] = "No tab with id: *."; | 16 const char kNoTabError[] = "No tab with id: *."; |
17 } | 17 } |
18 | 18 |
19 bool ClipboardFunction::RunImpl() { | 19 bool ClipboardFunction::RunImpl() { |
20 int tab_id; | 20 int tab_id; |
21 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); | 21 EXTENSION_FUNCTION_VALIDATE(args_->GetInteger(0, &tab_id)); |
22 | 22 |
23 TabContents* contents = NULL; | 23 TabContents* contents = NULL; |
24 if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), | 24 if (!ExtensionTabUtil::GetTabById(tab_id, profile(), include_incognito(), |
25 NULL, NULL, &contents, NULL)) { | 25 NULL, NULL, &contents, NULL)) { |
26 error_ = ExtensionErrorUtils::FormatErrorMessage(kNoTabError, | 26 error_ = ExtensionErrorUtils::FormatErrorMessage( |
27 IntToString(tab_id)); | 27 kNoTabError, base::IntToString(tab_id)); |
28 return false; | 28 return false; |
29 } | 29 } |
30 | 30 |
31 RenderViewHost* render_view_host = contents->render_view_host(); | 31 RenderViewHost* render_view_host = contents->render_view_host(); |
32 if (!render_view_host) { | 32 if (!render_view_host) { |
33 return false; | 33 return false; |
34 } | 34 } |
35 | 35 |
36 return RunImpl(render_view_host); | 36 return RunImpl(render_view_host); |
37 } | 37 } |
38 | 38 |
39 bool ExecuteCopyClipboardFunction::RunImpl(RenderViewHost* render_view_host) { | 39 bool ExecuteCopyClipboardFunction::RunImpl(RenderViewHost* render_view_host) { |
40 render_view_host->Copy(); | 40 render_view_host->Copy(); |
41 return true; | 41 return true; |
42 } | 42 } |
43 | 43 |
44 bool ExecuteCutClipboardFunction::RunImpl(RenderViewHost* render_view_host) { | 44 bool ExecuteCutClipboardFunction::RunImpl(RenderViewHost* render_view_host) { |
45 render_view_host->Cut(); | 45 render_view_host->Cut(); |
46 return true; | 46 return true; |
47 } | 47 } |
48 | 48 |
49 bool ExecutePasteClipboardFunction::RunImpl(RenderViewHost* render_view_host) { | 49 bool ExecutePasteClipboardFunction::RunImpl(RenderViewHost* render_view_host) { |
50 render_view_host->Paste(); | 50 render_view_host->Paste(); |
51 return true; | 51 return true; |
52 } | 52 } |
OLD | NEW |