summaryrefslogtreecommitdiffstats
path: root/webkit
diff options
context:
space:
mode:
Diffstat (limited to 'webkit')
-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());
+
+}
+