summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-02 20:26:05 +0000
committersverrir@google.com <sverrir@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-06-02 20:26:05 +0000
commitb952647d5b1d00a6b09979c2042e9e2061500d7b (patch)
tree485ee23af8c3576cbd0a75fb8b2bed5051e01252
parent9f5d0393b9239f0d2aba688bf3fa8524d545fde7 (diff)
downloadchromium_src-b952647d5b1d00a6b09979c2042e9e2061500d7b.zip
chromium_src-b952647d5b1d00a6b09979c2042e9e2061500d7b.tar.gz
chromium_src-b952647d5b1d00a6b09979c2042e9e2061500d7b.tar.bz2
Add functions to glue to get the full html of the page and also to check if the user has selected something.
This is for enhanced printing support (in progress). Review URL: http://codereview.chromium.org/119043 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@17427 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--webkit/glue/webframe.h7
-rw-r--r--webkit/glue/webframe_impl.cc10
-rw-r--r--webkit/glue/webframe_impl.h2
-rw-r--r--webkit/glue/webframe_unittest.cc38
4 files changed, 57 insertions, 0 deletions
diff --git a/webkit/glue/webframe.h b/webkit/glue/webframe.h
index cb65ae4..e630f35 100644
--- a/webkit/glue/webframe.h
+++ b/webkit/glue/webframe.h
@@ -326,10 +326,17 @@ class WebFrame {
// Clear any text selection in the frame.
virtual void ClearSelection() = 0;
+ // Checks if there is currently a selected area (indicates that GetSelection
+ // would return a non-empty string).
+ virtual bool HasSelection() = 0;
+
// Returns the selected text if there is any. If |as_html| is true, returns
// the selection as HTML. The return value is encoded in utf-8.
virtual std::string GetSelection(bool as_html) = 0;
+ // Returns the full HTML of the page.
+ virtual std::string GetFullPageHtml() = 0;
+
// Paints the contents of this web view in a bitmapped image. This image
// will not have plugins drawn. Devices are cheap to copy because the data is
// internally refcounted so we allocate and return a new copy
diff --git a/webkit/glue/webframe_impl.cc b/webkit/glue/webframe_impl.cc
index 086b2e6..f8ba7eb 100644
--- a/webkit/glue/webframe_impl.cc
+++ b/webkit/glue/webframe_impl.cc
@@ -1416,6 +1416,12 @@ void WebFrameImpl::ClearSelection() {
frame()->selection()->clear();
}
+bool WebFrameImpl::HasSelection() {
+ // frame()->selection()->isNone() never returns true.
+ return (frame()->selection()->start() !=
+ frame()->selection()->end());
+}
+
std::string WebFrameImpl::GetSelection(bool as_html) {
RefPtr<Range> range = frame()->selection()->toNormalizedRange();
if (!range.get())
@@ -1429,6 +1435,10 @@ std::string WebFrameImpl::GetSelection(bool as_html) {
}
}
+std::string WebFrameImpl::GetFullPageHtml() {
+ return webkit_glue::StringToStdString(createFullMarkup(frame_->document()));
+}
+
void WebFrameImpl::CreateFrameView() {
ASSERT(frame_); // If frame_ doesn't exist, we probably didn't init properly.
diff --git a/webkit/glue/webframe_impl.h b/webkit/glue/webframe_impl.h
index 3ec3f02..f2fee73 100644
--- a/webkit/glue/webframe_impl.h
+++ b/webkit/glue/webframe_impl.h
@@ -151,7 +151,9 @@ class WebFrameImpl : public WebFrame, public base::RefCounted<WebFrameImpl> {
virtual void Undo();
virtual void Redo();
virtual void ClearSelection();
+ virtual bool HasSelection();
virtual std::string GetSelection(bool as_html);
+ virtual std::string GetFullPageHtml();
virtual void SetInViewSourceMode(bool enable);
diff --git a/webkit/glue/webframe_unittest.cc b/webkit/glue/webframe_unittest.cc
index cbeb8e6..bc964b2 100644
--- a/webkit/glue/webframe_unittest.cc
+++ b/webkit/glue/webframe_unittest.cc
@@ -52,3 +52,41 @@ TEST_F(WebFrameTest, GetContentAsPlainText) {
frame->GetContentAsPlainText(12, &text);
EXPECT_EQ("Hello world", WideToUTF8(text));
}
+
+TEST_F(WebFrameTest, GetFullHtmlOfPage) {
+ WebView* view = test_shell_->webView();
+ WebFrame* frame = view->GetMainFrame();
+
+ // Generate a simple test case.
+ const char simple_source[] = "<p>Hello</p><p>World</p>";
+ GURL test_url("http://hello/");
+ frame->LoadHTMLString(simple_source, test_url);
+ test_shell_->WaitTestFinished();
+
+ std::wstring text;
+ frame->GetContentAsPlainText(std::numeric_limits<int>::max(), &text);
+ EXPECT_EQ("Hello\n\nWorld", WideToUTF8(text));
+
+ const std::string html = frame->GetFullPageHtml();
+
+ // Load again with the output html.
+ frame->LoadHTMLString(html, test_url);
+ test_shell_->WaitTestFinished();
+
+ EXPECT_EQ(html, frame->GetFullPageHtml());
+
+ text = L"";
+ frame->GetContentAsPlainText(std::numeric_limits<int>::max(), &text);
+ EXPECT_EQ("Hello\n\nWorld", WideToUTF8(text));
+
+ // Test selection check
+ EXPECT_FALSE(frame->HasSelection());
+ frame->SelectAll();
+ EXPECT_TRUE(frame->HasSelection());
+ frame->ClearSelection();
+ EXPECT_FALSE(frame->HasSelection());
+ std::string selection_html = frame->GetSelection(true);
+ EXPECT_TRUE(selection_html.empty());
+
+}
+